'The provided ARN is invalid' error when locally running a Step Function that calls EventBridge Scheduler

116 views Asked by At

I am running a Step Function using the AWS JS SDK v3 that gets and creates schedules with AWS EventBridge Scheduler. When I run it in the AWS account, I am able to run the step function.

However, when I set the endpoint to 'http://stepfunctions:8083', which is where the amazon/stepfunctions-local Docker container is running, I get the following error:

An error occurred while scheduling the state 'GetSchedule'. The provided ARN 'arn:aws:states:***********:aws-sdk:scheduler:getSchedule' is invalid.;

Following this tutorial to run the step function locally, I have defined a mock (using this guide) for the step that invokes EventBridge Scheduler. With the mock, I get the following error:

An error occurred while scheduling the state 'GetSchedule'. Could not find scheduler:getSchedule as aws sdk. Please refer to https://docs.aws.amazon.com/step-functions/latest/dg/connect-supported-services.html for valid service ARNs.

For many other step functions I have that are not calling EventBridge Scheduler or any other services that were supported around the same time (Feb 2023, as listed here), the SDK and the mocking framework work fine.

Things I have tried:

  • Using the latest version Docker image for stepfunctions-local
  • Updating the @aws-sdk/client-sfn version to the latest i.e. ^3.478.0
  • Installing @aws-sdk/client-scheduler along with all the other packages in the docker container where the tests are running

Here is my step function:

{
  "Comment": "Sample step func that fetches a schedule",
  "StartAt": "GetSchedule",
  "States": {
    "GetSchedule": {
      "Type": "Task",
      "End": true,
      "Parameters": {
        "Name": "my_sched_name"
      },
      "Resource": "arn:aws:states:::aws-sdk:scheduler:getSchedule"
    }
  }
}

My tests:

describe(`StepFunctions/${stepFunctionName}`, function () {
    let sfnWithDefinition;
    let sfnDirectlyOnAwsAccount;

    before(async () => {
        // The `StepFunction` class is just a helper that wraps AWS sfn-client commands
        sfnWithDefinition = new StepFunction({
            name: stepFunctionNameBase,
            definition: templatefile(
                `${stepFunctionsPath}/${stepFunctionName}.asl.json`,
                {},
            ),
        });
        await sfnWithDefinition.create();
        sfnDirectlyOnAwsAccount = new StepFunction({
            name: stepFunctionNameBase,
            mode: ExecutionMode.OnAwsAccount,
        });
    });


    it('step function when run locally WITHOUT mock returns error: The provided ARN \'arn:aws:states:eu-west-1:671446661642:aws-sdk:scheduler:getSchedule\' is invalid', async () => {
        const {response, history} = await sfnWithDefinition.execute({});
        console.log('history', history);
        const executionFailureDetails = getExecutionFailedDetails(history);
        const failureMessage = constructFailureMessage(executionFailureDetails);
        console.warn(failureMessage);
    });
    it('step function when run locally WITH mock returns error: Could not find scheduler:getSchedule as aws sdk. Please refer to https://docs.aws.amazon.com/step-functions/latest/dg/connect-supported-services.html for valid service ARNs.', async () => {
        const {response, history} = await sfnWithDefinition.execute({}, 'Mocking');
        console.log('history', history);
        const executionFailureDetails = getExecutionFailedDetails(history);
        const failureMessage = constructFailureMessage(executionFailureDetails);
        console.warn(failureMessage);
    });


    it('step function without definition with only ARN runs successfully on sandbox', async () => {
        const exc = await sfnDirectlyOnAwsAccount.executeOnCloud(sfnArn, {});
        console.log(exc);
        //EXECUTION IS CREATED SUCCESSFULLY IN AWS ACCOUNT
    });

    it('scheduler sdk directly fetches the schedule successfully', async () => {
        const schedConfig = {
            region: config.aws.region,
        };
        const client = new SchedulerClient(schedConfig);
        const input = {
            Name: "my_sched_name",
        };
        const command = new GetScheduleCommand(input);
        const response = await client.send(command);

        console.log(response);
    });
});

Question: Is there a way to make the step function be run locally when the step function invokes scheduler:* resources? Or is it a known missing feature in the amazon/stepfunctions-local? I couldn't find anything in the docs of the Docker image.

Alternatively, is there a workaround for this - e.g. another framework, or using HTTP integration instead of aws-sdk to call EventBridge Scheduler?

0

There are 0 answers