Learning Objectives:
- Learn how to build and operate serverless applications using Step Functions state machines
- See reference architectures, blueprints, and example use cases to get started quickly
- Know how to integrate Step Functions with other AWS services to develop and deploy applications faster
Are you building a serverless application with two or more Lambda functions? AWS Step Functions makes it easy to coordinate multiple functions and microservices as a series of steps using visual workflows. You create Step Functions state machines to specify and reliably step through the functions of your application at scale. In this deep-dive session, we will show how to use AWS CloudFormation and the AWS Serverless Application Model to deploy Step Functions state machines, AWS Lambda functions, and IAM roles and policies. We will demonstrate how Step Functions state machines orchestrate state transitions and error handling, and how state input/output works.
11. COORDINATION “MUST HAVES”
11AWS STEP FUNCTIONS
Scales Out Does Not Lose
State
Handles
Errors/Timeouts
Easy to Build/Operate Auditable
12. AWS STEP FUNCTIONS
12AWS STEP FUNCTIONS
…makes it easy to coordinate the
components of distributed applications
using visual workflows
13. BENEFITS OF AWS STEP FUNCTIONS
13AWS STEP FUNCTIONS
Diagnose and
debug problems
faster
Adapt to change
Easy to connect and
coordinate
distributed components
and microservices to
quickly create apps
Manages the
operations and
infrastructure of
service coordination
to ensure availability
at scale, and
under failure
Productivity Agility Resilience
14. APPLICATION LIFE CYCLE IN AWS STEP FUNCTIONS
14AWS STEP FUNCTIONS
Visualize in the
Console
Define in JSON Monitor
Executions
15. DEFINE IN JSON AND THEN VISUALIZE IN THE CONSOLE
15AWS STEP FUNCTIONS
{
”Comment”: “Hello World Example",
"StartAt” : "HelloWorld”,
"States” : {
"HelloWorld” : {
"Type” : "Task",
"Resource” :
"arn:aws:lambda:REGION:ACCOUNT_ID:function:FUNCTION_NAME
”,
"End” : true
}
}
}
16. EXECUTE ONE OR A MILLION
16AWS STEP FUNCTIONS
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
18. USE THROUGH THE API
18AWS STEP FUNCTIONS
Create
Upload state machines defined in JSON
Register activity workers
StartExecution Returns Execution ID
StopExecution
Stops a running state machine with
Execution ID
List All state machines, executions, and activities
Describe
Individual state machines, executions, and
activities
19. SEVEN STATE TYPES
19AWS STEP FUNCTIONS
Task A single unit of work
Choice Adds branching logic
Parallel Fork and join the data across tasks
Wait Delay for a specified time
Fail Stops an execution and marks it as a failure
Succeed Stops an execution successfully
Pass Passes its input to its output
20. BUILD VISUAL WORKFLOWS USING STATE TYPES
20AWS STEP FUNCTIONS
Task
Choice
Fail
ParallelMountains
People
Snow
21. TASK STATES: POLL OR PUSH
21AWS STEP FUNCTIONS
AWS Lambda
…On-premises
AWS container, EC2
instance, or… Long poll
Push
37. ANATOMY OF A STATE
37AWS STEP FUNCTIONS
State [x]"InputPath" "ResultPath" "OutputPath"
Input
Output
InputPath and OutputPath processes JSON
ResultPath places results into JSON
39. WHAT HAPPENS WHEN…
39AWS STEP FUNCTIONS
Q: InputPath not provided?
A: State gets raw input as-is.
Q: InputPath is null?
A: State gets an empty JSON object: {}
Q: InputPath produces plural output?
A: State gets it wrapped in a JSON array.
40. RESULT PLACEMENT
40AWS STEP FUNCTIONS
{
"title": "Numbers to add",
"numbers": [ 3, 4 ]
}
{
"Type": "Task",
"InputPath": "$.numbers",
"ResultPath": "$.sum”,
…
Raw input:
State spec:
Output:
{
"title": "Numbers to add",
"numbers": [ 3, 4 ],
"sum": 7
}
41. OUTPUT PROCESSING
41AWS STEP FUNCTIONS
{
"title": "Numbers to add",
"numbers": [ 3, 4 ]
}
{
"Type": "Task",
"InputPath": "$.numbers",
"ResultPath": "$.sum”,
"OutputPath": “$.title, $.sum”
Raw input:
State spec:
Output:
{
"title": "Numbers to add",
"sum": 7
}
42. WHAT HAPPENS WHEN…
42AWS STEP FUNCTIONS
Q: ResultPath not provided?
A: Input discarded, raw output used.
Q: ResultPath is null?
A: State input is state output.
Q: ResultPath produces plural output?
A: Not allowed, validator won’t accept.
45. COMMON PATTERNS
45AWS STEP FUNCTIONS
• Use Choice states for looping
• Use Pass states to inject values into state
• Manage API uncertainty with Retries
• Use Step Functions where shell scripts would make you nervous
• Parallelize where possible
• Write mini Lambda-functions for JSON mangling
• Generate state machine JSON from building blocks
46. TIPS
46AWS STEP FUNCTIONS
• Don’t try/catch too much at the Lambda level.
• Don’t call Lambda from Lambda without asking:
Can this be done by Step Functions?
• Do decompose larger applications/scripts into an SFN state machine and a
set of Lambda functions.
• Do use SAM to manage many small Lambda functions.
• Do automate your state machine JSON builds.