This presentation describes the different pieces of the puzzle needed to unit test a Step Functions state machine defined with CDK code.
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkJerome Van Der Linden (@jeromevdl)Automate Local Testing of CDK-definedStep FunctionsSolutions Architect Builder @ AWS
View Slide
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkWho am I ?Jérôme Van Der LindenSolutions Architect Builder @ AWS (Geneva, Switzerland)Former consultant, developer, tech lead, agile & devopscoach, architect @ OCTO TechnologyHusband and Dad of 3jeromevdl
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkObjec8ves• Unit testing AWS Step Functions State Machines• Defined with CDK code• Locally without reaching the cloud• Automate as much as possible the process
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkBig Picture
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkCDK-defined Step Functions State Machine
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkCDK Deploy
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkCDK DeploySince I recorded this video, Idiscovered cdk-asl-extractorIt permits to retrieve the ASL withoutdeploying the stack. 😀🤩Use cdk synth to get theCloudFormation templateand use cdk-asl-extractorto get the ASL from the template.
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkOutputs🌀🌩☠❗💥🤯output.jsonStack name Output name Randomly generated stringConstructname
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkExtracting the State Machine definitionRocks!
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkState Machine definitionstate_machine.asl.json
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkWrap-up: CDK code to JSON ASL
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkMocked service integrationMockConfigFile.jsonState Machine nameMocked statesMocked responses namesMocked responses definitions
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkStep Func8ons LocalStart stepfunctions-local:Mocked Configuration
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkStep Functions LocalCreate the state machine locally:State machine definition(ASL / JSON)State Machine name(same as in the MockConfigFile.json)
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkWrap-up: Step-Func8ons local bootstrap
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkUnit TestsState Machine name(same as in the MockConfigFile.json)Test case name(same as in the MockConfigFile.json)Local endpoint
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkUnit TestsTest case name(same as in the MockConfigFile.json)
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkWrap-up
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkWrap-up1. Retrieve the state machine ASLfrom the CDK code
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkWrap-up1. Retrieve the state machine ASLfrom the CDK code2. Create Mocked Serviceintegration config
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkWrap-up1. Retrieve the state machine ASLfrom the CDK code2. Create Mocked Serviceintegration config3. Start Step Functions local withthis mocked configuration4. Create a State Machine locally
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkWrap-up1. Retrieve the state machine ASLfrom the CDK code2. Create Mocked Serviceintegration config3. Start Step Functions local withthis mocked configuration4. Create a State Machine locally5. Run your tests (using the SDK)
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkResources
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and Trademark• Testing Step Functions State Machines Locally• https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local.html• Using Mocked Service Integrations• https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local-test-sm-exec.html• Mocking service integrations with AWS Step Functions Local• https://aws.amazon.com/blogs/compute/mocking-service-integrations-with-aws-step-functions-local/• Code Sample GitHub• https://github.com/aws-samples/step-functions-direct-integrations/tree/main/direct-integration/infra
© 2022, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and Trademark© 2019, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Confidential and TrademarkThank youjeromevdlJérôme Van Der Linden