Hey Teacher
Hey Teacher

Reputation: 1225

run locally Step Function defined in a SAM template

I follow the guide https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local-lambda.html to run locally a Step Function defined inline.

But I don't found any guide how to test locally a Step Function defined into a SAM template (template.yaml).

Is it possible?

Upvotes: 4

Views: 1034

Answers (2)

Vinícius Knob
Vinícius Knob

Reputation: 23

You can use the SDK for the desired language and create your automated tests by following the documentation: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/StepFunctions.html.

Node.js example:

const stepfunctions = new AWS.StepFunctions({endpoint: 'http://localhost:8083'});

Other option is use AWS CLI with bash/sh files and creating manual (strange) tests that it can be invoked by "npm run", like: https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local-lambda.html.

$ aws stepfunctions --endpoint http://localhost:8083 <command>

Upvotes: 0

Allen
Allen

Reputation: 4749

Currently Step Functions integration with SAM is still at an early phase. It offers following functionalities from the documentation:

Get started in minutes using a AWS SAM sample template.

Build your state machine into your serverless application.

Use variable substitution to substitute ARNs into your state machine at time of deployment.

Simplify specifying your state machine role using AWS SAM policy templates.

Trigger state machine executions with API Gateway, EventBridge events, or on a schedule within your AWS SAM template.

However, unlike you can use SAM local to emulate Lambda and API Gateway locally, you cannot emulate Step Functions locally using SAM.

Step Functions Local is the only officially supported way to test your state machines locally, pairing with SAM local command, you can use the local version of Step Functions invoking a local version of AWS Lambda.

Upvotes: 2

Related Questions