Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Local testing of CDK-defined Step Functions sta...

Local testing of CDK-defined Step Functions state machine

This presentation describes the different pieces of the puzzle needed to unit test a Step Functions state machine defined with CDK code.

Tweet

More Decks by Jérôme Van Der Linden

Other Decks in Technology

Transcript

  1. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Jerome Van Der Linden (@jeromevdl) Automate Local Testing of CDK-defined Step Functions Solutions Architect Builder @ AWS
  2. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Who am I ? Jérôme Van Der Linden Solutions Architect Builder @ AWS (Geneva, Switzerland) Former consultant, developer, tech lead, agile & devops coach, architect @ OCTO Technology Husband and Dad of 3 jeromevdl
  3. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Objec8ves • Unit testing AWS Step Functions State Machines • Defined with CDK code • Locally without reaching the cloud • Automate as much as possible the process
  4. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Big Picture
  5. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Big Picture
  6. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark CDK-defined Step Functions State Machine
  7. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark CDK-defined Step Functions State Machine
  8. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark CDK-defined Step Functions State Machine
  9. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark CDK Deploy
  10. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark CDK Deploy Since I recorded this video, I discovered cdk-asl-extractor It permits to retrieve the ASL without deploying the stack. 😀🤩 Use cdk synth to get the CloudFormation template and use cdk-asl-extractor to get the ASL from the template.
  11. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Outputs 🌀🌩☠ ❗💥🤯 output.json Stack name Output name Randomly generated string Construct name
  12. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Extracting the State Machine definition Rocks!
  13. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark State Machine definition state_machine.asl.json
  14. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Wrap-up: CDK code to JSON ASL
  15. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Mocked service integration MockConfigFile.json State Machine name Mocked states Mocked responses names Mocked responses definitions
  16. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Step Func8ons Local Start stepfunctions-local: Mocked Configuration
  17. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Step Functions Local Create the state machine locally: State machine definition (ASL / JSON) State Machine name (same as in the MockConfigFile.json)
  18. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Wrap-up: Step-Func8ons local bootstrap
  19. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Unit Tests State Machine name (same as in the MockConfigFile.json) Test case name (same as in the MockConfigFile.json) Local endpoint
  20. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Unit Tests Test case name (same as in the MockConfigFile.json)
  21. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Wrap-up
  22. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Wrap-up 1. Retrieve the state machine ASL from the CDK code
  23. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Wrap-up 1. Retrieve the state machine ASL from the CDK code 2. Create Mocked Service integration config
  24. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Wrap-up 1. Retrieve the state machine ASL from the CDK code 2. Create Mocked Service integration config 3. Start Step Functions local with this mocked configuration 4. Create a State Machine locally
  25. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Wrap-up 1. Retrieve the state machine ASL from the CDK code 2. Create Mocked Service integration config 3. Start Step Functions local with this mocked configuration 4. Create a State Machine locally 5. Run your tests (using the SDK)
  26. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Wrap-up 1. Retrieve the state machine ASL from the CDK code 2. Create Mocked Service integration config 3. Start Step Functions local with this mocked configuration 4. Create a State Machine locally 5. Run your tests (using the SDK)
  27. © 2022, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Amazon Confidential and Trademark Resources
  28. © 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
  29. © 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 Trademark Thank you jeromevdl Jérôme Van Der Linden