Slide 1

Slide 1 text

© 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

Slide 2

Slide 2 text

© 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

Slide 3

Slide 3 text

© 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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

© 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.

Slide 11

Slide 11 text

© 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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

© 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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

© 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)

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

© 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

Slide 20

Slide 20 text

© 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)

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

© 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

Slide 23

Slide 23 text

© 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

Slide 24

Slide 24 text

© 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

Slide 25

Slide 25 text

© 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)

Slide 26

Slide 26 text

© 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)

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

© 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

Slide 29

Slide 29 text

© 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