John
John

Reputation: 11831

Is there a way of running AWS Step Functions locally when defined by CDK?

AWS Step Functions may be run in a local Docker environment using Step Functions Local Docker. However, the step functions need to be defined using the JSON-based Amazon States Language. This is not at all convenient if your AWS infrastructure (Step Functions plus lambdas) is defined using AWS CDK/CloudFormation.

Is there a way to create the Amazon States Language definition of a state machine from the CDK or CloudFormation output, such that it’s possible to run the step functions locally?

My development cycle is currently taking me 30 minutes to build/deploy/run my Lambda-based step functions in AWS in order to test them and there must surely be a better/faster way of testing them than this.

Upvotes: 13

Views: 5242

Answers (3)

Alexander Medved
Alexander Medved

Reputation: 1

Another solution that might help is to use localstack what is supports many tools such CDK or CloudFormation and let developers to run stack locally.

There are a variety ways to run it, one of them is to run it manually in docker container, according to the instruction get started.

Next following the instruction what's next configure aws-cli or use awslocal.

All next steps and templates should be the same as for AWS API in the cloud.

Upvotes: 0

adamwong
adamwong

Reputation: 1194

You can use cdk watch or the --hotswap option to deploy your updated state machine or Lambda functions without a CloudFormation deployment.

https://aws.amazon.com/blogs/developer/increasing-development-speed-with-cdk-watch/

If you want to test with Step Functions local, cdk synth generates the CloudFormation code containing the state machine's ASL JSON definition. If you get that and replace the CloudFormation references and intrinsic functions, you can use it to create and execute the state machine in Step Functions Local.

How some people have automated this:

Upvotes: 4

Matthew Dorrian
Matthew Dorrian

Reputation: 21

We have been able to achieve this by the following:

Download:

https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local.html

To run step functions local, in the directory where you extracted the local Step Function files run:

java -jar StepFunctionsLocal.jar --lambda-endpoint http://localhost:3003

To create a state machine, you need a json definition (It can be pulled from the generated template or can get the toolkit plug in for Vs code, type step functions, select from a template and that can be your starter. Can also get it from the AWS console in the definition tab on the step function.

Run this command in the same directory as the definition json:

aws stepfunctions --endpoint http://localhost:8083 create-state-machine --definition "cat step-function.json" --name "local-state-machine" --role-arn "arn:aws:iam::012345678901:role/DummyRole"

You should be able to hit the SF now (hopefully) :)

Upvotes: 2

Related Questions