

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.


The art of the state: Coordinating
services using AWS Step Functions
Gabe Hollombe
Senior Developer Advocate
Amazon Web Services
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.


"AWS Step Functions gives us a reliable, automated way of
orchestrating very complex queries and processes among all our
distributed systems, Brown says. We saved time and money by
making it easy for our developers to build applications using AWS
Lambda functions, giving them more productivity and agility. We
also get a visual representation of the logic for each workflow, which
makes it easier when discussing the solution with nontechnical
stakeholders at the company."
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.


"AWS Step Functions gives us a reliable, automated way of
orchestrating very complex queries and processes among all our
distributed systems, Brown says. We saved time and money by
making it easy for our developers to build applications using AWS
Lambda functions, giving them more productivity and agility. We
also get a visual representation of the logic for each workflow, which
makes it easier when discussing the solution with nontechnical
stakeholders at the company."
Paul Brown
Senior Developer Manager
What we'll cover in this session
Background and challenges around working with distributed services
Introducing the concept of orchestration
Service orchestration made easy using state machines
AWS Step Functions: State machines in the cloud
Examples from the real world
Where to learn more
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.


In a monolith, everything gets deployed together
With microservices, we split the work
among multiple systems
Microservices can give us increased
agility and scalability
But distributed systems can be harder
to coordinate and debug
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.


Here's a simplified banking system
Account
applications
Accounts
Create account
Data
checking
Check identity docs
Check address
Human review
List flagged applications
Handle human decisions
Accept new application
Consolidate data checks
Human review
Approve or Reject
Processing a new account application
requires some coordination
Account
applications
Accounts
Create account
Data
checking
Check identity docs
Check address
Human review
List flagged applications
Handle human decisions
Accept new application
Consolidate data checks
Human review
Approve or Reject
Orchestration: One process manages workflow state
and calls appropriate services in turn
Account
applications
Accounts
Data
checking
Human
review
Orchestration: One process manages workflow state
and calls appropriate services in turn
Account
applications
Accounts
Data
checking
Check identity
Human
review
Orchestration: One process manages workflow state
and calls appropriate services in turn
Account
applications
Accounts
Data
checking
Check identity
Check address
Human
review
Orchestration: One process manages workflow state
and calls appropriate services in turn
Account
applications
Accounts
Data
checking
Check identity
Check address
Human review
Human
review
Orchestration: One process manages workflow state
and calls appropriate services in turn
Account
applications
Accounts
Data
checking
Check identity
Check address
Human review
Create account
Human
review
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.


A state machine
Describes a collection of computational
steps split into discrete states
Has one starting state and
always one active state (while executing)
The active state receives input,
takes some action, and generates output
Transitions between states are based on
state outputs and rules that we define
AWS Step Functions
Resilient workflow automation
Built-in error handling
Powerful AWS service integration
First-class support for integrating with
your own services
Auditable execution history and visual monitoring
Fully managed state machines on AWS
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.


How AWS Step Functions work
The workflows you build with Step Functions are called state
machines, and each step of your workflow is called a state
When you execute your state machine, each move from one
state to the next is called a state transition
You can reuse components, easily edit the sequence of steps or
swap out the code called by task states as your needs change
Amazon States Language
https://states-language.net/spec.html
{
"Comment": "A simple minimal example",
"StartAt": "Hello World",
"States": {
"Hello World": {
"Type": "Task",
"Resource": "arn:aws:lambda...HelloWorld",
"End": true
},
[. . .]
}
}
Example workflow: Opening
an account
Wait for a callback
Parallel steps
Branching choice
Tasks
Performing a task
Call an AWS Lambda function
Wait for a polling worker to
perform an activity
Pass parameters to an API of
an integrated AWS service
Performing a task
Example: Execute a AWS Lambda function
"Verify identity documents": {
"Type": "Task",
"Parameters": {
"name.$": "$.application.name"
"identityDoc.$": "$.application.idDocS3path"
},
"Resource": "arn:aws:lambda...VerifyIdDocs",
"End": true
}
Executing branches
in parallel
Contains an array of state
machines branches to
execute in parallel
Outputs an array of outputs
from each state machine in
its branches
Executing branches
in parallel
Example: Run two branches in parallel
"Perform Automated Checks": {
"Type": "Parallel",
"Branches": [
{
"StartAt": "Verify identity documents",
"States": { "Verify identity documents": { … } }
},
{
"StartAt": "Check Address",
"States": { "Check Address": { … } }
}
]
},
"ResultPath": "$.checks",
"Next": "Human Review Required?"
}
Making a choice
Like a switch statement in
programming
Inspects an array of
choice
expressions, comparing
variables to values
Determines which state to
transition to next
Making a choice
Example: Choose next step based on
state outputs
"Human Review Required?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.checks[0].flagged",
"BooleanEquals": true,
"Next": "Wait For Review"
},
{
"Variable": "$.checks[1].flagged",
"BooleanEquals": true,
"Next": "Wait For Review"
}
],
"Default": "Approve Application"
}
Waiting for a callback
Generates a task token and
passes it to an integrated
service
When the recipient process is
complete, it calls
SendTaskSuccess or
SendTaskFailure with the task
token
Workflow then resumes its
execution
Waiting for a callback
Example: Pause and wait for an
external callback
"Type": "Task",
"Resource":"arn:aws:states:::lambda:invoke.wait
ForTaskToken",
"Parameters": {
"FunctionName": "FlagApplicationForReview",
"Payload": {
"applicationId.$": "$.application.id",
"taskToken.$": "$$.Task.Token"
}
},
"ResultPath": "$.reviewDecision",
"Next": "ReviewApproved?"
Error handling
Failures can happen due to Timeouts,
Failed Tasks, or Insufficient Permission
Tasks can Retry when errors occur using a
BackoffRate up to MaxAttempts
Tasks can Catch specific errors and
transition to other states
Working with AWS Step Functions
Visualize in the console
Define in JSON Monitor executions
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.


State types
Task
Execute
work
Choice
Add
branching logic
Wait
Add
a timed delay
Parallel
Execute
branches in parallel
Map
Process
each of an input array's items with a state machine
Succeed
Signal
a successful execution and stop
Fail
Signal
a failed execution and stop
Pass
Pass
input to output
AWS Step Functions service integrations
Amazon
Elastic Container Service
AWS
Lambda
AWS
Batch
Amazon
DynamoDB
Amazon
SageMaker
AWS
Glue
AWS
Step Functions
Amazon
Simple Notification Service
Amazon
Simple Queue Service
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.


https://www.youtube.com/watch?v=ICEhR3mshyg
On-demand, audited host access pipeline
When an operator needs to into an
environment, they authenticate and request permission
An AWS Step Function notifies the required actor and waits
for an approval response that initiates the provisioning of a
securely configured bastion host
It also starts a timer that ensures that the bastion
environment is cleaned up in a timely manner
https://www.youtube.com/watch?v=sMaqd5J69Ns
Shortened processing time for updating nutrition
labels from 36 hours to 10 seconds
Data validation and transformation steps are
designed visually with nontechnical personnel
Validation and transformation steps verified in
real time as data flows through the state machine
Process optimizations are identified and
implemented on the spot
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.


AWS Step Functions Express Workflows
Orchestrate AWS compute, database, and messaging services at rates up to
100,000 events per second, suitable for high-volume event processing workloads,
such as IoT data ingestion, microservices orchestration, and streaming data
processing and transformation
NEW
Standard vs. Express Workflows
Standard
Express
Maximum
duration
365 days
5 minutes
Execution
start rate
Over 2,000 per second
Over 100,000 per second
State
transition
rate
Over 4,000 per second
per account
Nearly unlimited
Execution
semantics

workflow
execution

workflow
execution
Standard vs. Express Workflows (continued)
Standard
Express
Executions
Executions are persisted and have
ARNs
Executions are not persisted except
as log data
Execution
history
Stored in Step Functions, with
tooling for visual debugging
in the console
Sent to Amazon CloudWatch Logs
Service
integrations
Supports all service integrations
and activities
Supports all service integrations
Does not support activities
Patterns
Supports all patterns
Does not support Job-run (.sync) or
Callback (.wait For Callback)
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.


Development tips
AWS Step Functions local
https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local.html
Statelint
https://github.com/awslabs/statelint
Serverless framework plug-in
https://github.com/horike37/serverless-step-functions
Visual Studio code
aws-step-functions-constructor extension
https://marketplace.visualstudio.com/items?itemName=paulshestakov.aws-step-functions-constructor
Get started building with AWS Step Functions
Workshop: Intro to Service Coordination ~2 hours
https://step-functions-workshop.go-aws.com/
Developer guide ~2 hours
https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html
Reference architectures
https://aws.amazon.com/step-functions/resources/
AWS Step Functions key benefits
Fully managed service
High availability & automatic scaling
Visual monitoring & state management
Auditable execution history
Built-in error handling
Pay per use
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.


Thank you!
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.


Gabe Hollombe
@gabehollombe