Search code examples
javascriptnode.jsamazon-web-servicesaws-sdkaws-step-functions

Why is my aws step function's execution not started with the ARN I entered?


I'm creating a new state machine with AWS Step functions in the project I'm working on. But when I try to start the execution of the step function with the aws-sdk, I get a "StateMachineDoesNotExist" error. It seems like the stateMachineArn I pass as input is not the same used by the startExecution function.

Here is how I'm trying to start the execution:

const AWS = require('aws-sdk') 
const stepfunctions = new AWS.StepFunctions()

  const params = {
    stateMachineArn: process.env.ORDER_ACCEPTED_MACHINE_ARN,
    name: `${orderId}-${moment().unix()}`,
    input: JSON.stringify({
      orderAcceptedTimestamp: moment(createdAt).add(1, 'minutes').toISOString(),
      orderId,
    }),
  }

  const success = await stepfunctions.startExecution(params).promise()
  return success.executionArn

My stateMachineArn is defined this way :

process.env.ORDER_ACCEPTED_MACHINE_ARN = 'arn:aws:states:eu-central-1:935080471983:stateMachine:orderAcceptedMachine-dev'

And here is the error message I get when running the code:

State Machine Does Not Exist: 'arn:aws:states:us-east-1:935080471983:stateMachine:orderAcceptedMachine-dev'

What I don't understand here is that the Arn from the input and the Arn from the error are not the same. To me it seems like the startExecution modified the input stateMachineArn and changed its region somehow (even though the Arn is passed as a string?!).

I already have a similar step functions in the project that I start the same way:

const params = {
    stateMachineArn: process.env.ORDER_TIMEOUT_MACHINE_ARN,
    name: `${orderId}-${moment().unix()}`,
    input: JSON.stringify({
      orderTimeoutTimestamp: timeout.toISOString(),
      orderId,
    }),
  }

    const success = await stepfunctions.startExecution(params).promise()
    return success.executionArn

The Arn definition is in the same file as the other one, and is defined like this:

process.env.ORDER_TIMEOUT_MACHINE_ARN = 'arn:aws:states:eu-central-1:935080471983:stateMachine:orderTimeoutMachine-dev'

This step functions is started with no problem and correctly return the Arn of the execution.

By debugging I found out that AWS.config.region returns us-east-1 in both files where I call startExecution. Since my existing state machine is already working with this configuration, I'm thinking it's not related to the error, but I tried to 'force' the AWS Region to eu-central-1 anyway just before the call like this:

    AWS.config.update({ region: 'eu-central-1' })
    const success = await stepfunctions.startExecution(params).promise()

But this doesn't solve the issue. I am fairly new to AWS so there is probably something that I'm missing out here (Let me know if I forgot to put any important code/info), but I'm really confused by the facts that the Arn in the error message doesn't match the one in the input, and that an almost identical state machine is working fine while my newly created one doesn't want to start.

So how can I fix this issue ?


Solution

  • After further investigation I found out that the step functions's region and endpoint can be different from AWS. Adding the following code solved the issue:

    const stepfunctions = new AWS.StepFunctions({
      endpoint: 'https://states.eu-central-1.amazonaws.com',
      region: 'eu-central-1',
    })