/sam-stepfunctions-sdk-integration

Create a state machine using AWS SAM and the AWS SDK service integrations. Learn how to do unit tests of your state machines.

Primary LanguageMakefileMIT LicenseMIT

AWS Step Functions - SDK Integrations

Infrastructure as code framework used: AWS SAM, ASL

AWS Services used: AWS Step functions, Amazon S3, Amazon Transcribe, Amazon Transcribe, Amazon Translate

Summary of the demo

This is a sample application which showcases how to use Step Functions with AWS SAM, SDK integrations and local testing using mock configs.

In this example you won't find any Lambda function, but instead direct calls from the state machine to the different AWS Services.

We are also showing how to test locally the state machine, using mock configs. Mock configs allows a developer to mock the output of service integrations that are present in a state machine.

Developers can provide a valid sample output from the service call API that is present in the state machine as mock data. This allows developers to test the behavior of the state machine in isolation.

In this demo you will see:

  • How to create a State Machine using ASL and the AWS SDK integrations
  • How to define a state machine using AWS SAM
  • How to transcribe an existing video/audio file and translate it into spanish
  • How to test locally a State Machine
  • How to create a MockConfigFile
  • How to run this automatically

This demo is part of a video series posted in FooBar Serverless channel. You can check the videos to see the whole demo.

Overview of the state machine

This state machine takes a video or audio in English, stored in an S3 bucket. Transcribe this file with Amazon Transcribe, then grabs the transcriptions and gets the transcript for the text using Amazon Transcribe. And finally with the transcribed text uses Amazon Translate to get the spanish version of the text.

StateMachine

Deploy this demo

We will be using AWS SAM and make sure you are running the latest version - at the time of writing, this was 1.37.0 (sam --version).

Deploy the project to the cloud:

sam deploy -g # Guided deployments

You will need to input the S3 bucket and object key where your audio/video file is stored.

Next times, when you update the code, you can build and deploy with:

sam deploy

To delete the app:

sam delete

Test locally

To test the state machine locally you will first need to download the step functions local docker image.

Following the user guide, you can either run Step Functions local as a JAR or as a Docker container. Steps below will focus on the docker container approach.

docker pull amazon/aws-stepfunctions-local

Then you can run all the tests in the makefile

On a terminal window, first start with running docker:

make run

On a different terminal window/tab, you can then run:

make all

Finally, you can check history of each execution by running:

make history

Check makefile for details

Links related to this code