Skip to content

Files

Latest commit

 

History

History

18-step-functions

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Topic 18: Step Functions

Guidance

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

Lesson 18.1: Introduction to Step Functions

Principle 18.1

AWS Step Functions is a web service that enables you to coordinate the components of distributed applications and microservices using visual workflows.

Practice 18.1

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.

Lab 18.1.1: Create a State Machine in the AWS Console

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.

Question: Pass State

Describe the "Pass" state and what it does.

Question: States

What are some of the other states you can use in a state machine?

Question: Input and Output

Describe how input and output are handled and manipulated in the step functions.

Retrospective 18.1

Question: Workflows

When choosing a workflow when is it recommended to use an Express workflow versus the Standard workflow?

Lesson 18.2: Lambda State Machine

Principle 18.2

AWS Step Functions state machine can use an AWS Lambda function to implement a Task state.

Practice 18.2

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.

Lab 18.2.1: Create a Lambda State Machine with CloudFormation

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!"

Question: Activity State Machine

What are some use cases for using an Activity State Machine instead of the Lambda State Machine?

Retrospective 18.2

Question: Service Integrations

What are some other supported AWS service integrations for Step Functions?

Lesson 18.3: Step Functions and Events

Principle 18.3

You can use Amazon CloudWatch Events to execute an AWS Step Functions state machine in response to an event or on a schedule.

Practice 18.3

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.

Lab 18.3.1: Start an Execution in Response to a S3 Event

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.

Retrospective 18.3

Question: Other Events

What are other types of events that can be used to trigger a state machine execution?

Further Reading