- Topic 18: Step Functions
-
Explore the official docs! See the AWS Step Functions Developer Guide, API Reference, and CLI Reference docs.
-
Avoid using other sites like stackoverflow.com for answers -- part of the skill set you're building is finding answers straight from the source, AWS.
-
Explore your curiosity. Try to understand why things work the way they do. Read more of the documentation than just what you need to find the answers.
AWS Step Functions is a web service that enables you to coordinate the components of distributed applications and microservices using visual workflows.
Step Functions provides a reliable way to coordinate components and step through the functions of your application. They are based on the concepts of tasks and state machines, which are defined using the JSON-based Amazon States Language. The Step Functions console displays a graphical view of your state machine's structure. This provides a way to visually check your state machine's logic and monitor executions.
Create a simple State Machine using the AWS console.
-
Use the default "Author with code snippets" for Define state machine.
-
Use the default "Standard" for Type.
-
Update the code snippet to accept an input JSON property named executioner and output the following JSON object: { "executioner": "Your Name", "message": "Hello AWS!" }
-
Give your state machine an appropriate name.
-
Make a note of the new IAM role being created. You will need this when cleaning up the lab resources.
-
Review the results and look at the step details after executing your state machine. Does the output look as expected?
-
When you're done, delete the state machine and the IAM role.
Describe the "Pass" state and what it does.
What are some of the other states you can use in a state machine?
Describe how input and output are handled and manipulated in the step functions.
When choosing a workflow when is it recommended to use an Express workflow versus the Standard workflow?
AWS Step Functions state machine can use an AWS Lambda function to implement a Task state.
AWS Lambdas are well suited for implementing Task states, because Lambda functions are stateless (they have a predictable input-output relationship), easy to write, and don't require deploying code to a server instance.
Create a CFN template that creates a state machine, a lambda, and the required IAM roles for those services when the stack is created:
-
Lambda should return "Hello AWS!".
-
The state machine should use the Lambda function to implement a task state.
-
State machine execution should output "Hello AWS!"
What are some use cases for using an Activity State Machine instead of the Lambda State Machine?
What are some other supported AWS service integrations for Step Functions?
You can use Amazon CloudWatch Events to execute an AWS Step Functions state machine in response to an event or on a schedule.
CloudWatch Events, such as uploading a new object to a S3 bucket, can be used to trigger the execution of a state machine. This type of function could be useful if you needed to perform operations on files that are added to a bucket. This is also only a single example of the many types of events that can trigger a state machine.
Using the CFN template from the previous lab, make the following changes:
-
Create a new S3 bucket.
-
Create a new trail in CloudTrail that logs the events that occur in your new S3 bucket.
-
Create a new CloudWatch rule to trigger the state machine when a file is uploaded to your new S3 bucket.
-
Update the Lambda to return the name of the file uploaded.
-
After the stack is updated, upload a file to your new S3 bucket and then review the execution log for your state machine execution.
-
When you're done, delete the stack and all resources you created for these labs.
What are other types of events that can be used to trigger a state machine execution?
-
Read about SAM integration for testing your step functions locally.
-
Learn more about handling error conditions in a state machine.