SlideShare ist ein Scribd-Unternehmen logo
1 von 41
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Adam Larter
Principal Solutions Architect, Developer Specialist
www.linkedin.com/in/adamlarter/
Real-world development
AWS Step Functions and Distributed Complexity
E X P R E S S
D E V L O U N G E
• Distributed complexity and the challenges it introduces
• Orchestrating async state machines with AWS Step Functions
• Throwing and handling exceptions in AWS Step Functions
• Triggering state machine workflows in response to events
• Using AWS X-ray to analyse the calls and performance
of Step Functions workflows
• Lots of code and demos!
LEARNING OBJECTIVES
D E V L O U N G E
Distributed Complexity
D E V L O U N G E
Serverless microservices
AWS LambdaAmazon API
Gateway
• Highly available
• Scalable
• Fault tolerant
• Cost effective
• Secure
Microservice
Challenges:
• Stateless
• Discrete / isolated data stores
• Distributed / asynchronous
D E V L O U N G E
Challenge: Transactional Integrity
• How do we handle transactional integrity?
• Polyglot persistence generally translates into
eventual consistency
• Asynchronous calls allow non-blocking, but
return data (state) needs to be propagated
• What about failures and retries?
ERROR
STATE?
ROLLBACK?
D E V L O U N G E
Challenge: Multi-stage long-running tasks
• Tasks that require co-ordination across multiple systems
through multiple states
• Tasks that may require manual intervention
• Tasks that are expected to be long-running
and take hours/days/months to resolve
• Tasks that are expected to periodically fail
and need to be retried as a matter of course
D E V L O U N G E
Building applications out of distributed functions
• “I want to sequence functions”
• “I want to run functions in parallel”
• “I want to select functions based on input data or current state”
• “I want to retry functions with backoff”
• “I want try/catch/finally”
• “I have code that runs for hours or needs manual intervention”
Coordination of asynchronous functions
D E V L O U N G E
Coordination by function chaining
Lambda function A B
C
D
EF
G
D E V L O U N G E
Coordination by function chaining
Lambda function A B
C
D
EF
G
D E V L O U N G E
Coordination by database
Amazon DynamoDB
AWS Lambda
function
D E V L O U N G E
Coordination by queues
Amazon
SQS
AWS Lambda
function
D E V L O U N G E
What would an orchestration solution look like?
• Scales out
• Doesn’t lose state
• Deals with errors/timeouts/retries
• Easy to build & operate – declarative, not code-based
• Automatable
• Auditable
• Visible and traceable
Coordination must-haves
D E V L O U N G E
• Fully managed service
making it easy to coordinate the
components of distributed applications
and microservices using visual workflows
• You construct your application’s flows
as a state machine, a series of
steps that together capture the
behavior of the application
AWS Step Functions
D E V L O U N G E
AWS Step Functions: State types
Parallel Steps Choice State Catch Failure
Retry Failure Wait State
D E V L O U N G E
Example: “Calculator” State Machine
D E V L O U N G E
Quick anatomy of a state machine
• Each state is named uniquely but arbitrarily
• StartAt – the entry point
• Each state has a type – Choice, Pass, Parallel, Fail, Wait, Task…
• Every non-fatal state has a Next state
• A fatal state is denoted by End:true or Type:Fail
• Task states have a Resource attribute that defines
how the state will complete
• Tasks can declare a Retry clause based on the type of
application-defined error that has occurred
D E V L O U N G E
“I want to retry functions”
We get transient errors from a RESTful
service we depend on, once every four or
five times we call it. But if we keep retrying,
it eventually works.
‘
’
D E V L O U N G E
{
"Comment": "Call out to a RESTful service",
"StartAt": "Call out",
"States": {
"Call out": {
"Type": "Task",
"Resource":
"arn:aws:lambda:ap-southeast-2:123456789012:function:RESTCall",
"Retry": [
{ "ErrorEquals": [ ”MyTransientError" ], "MaxAttempts": 10 }
],
"End": true
}
}
}
AWS Step Functions: Error Handling & Retries
D E V L O U N G E
“I want to run functions in parallel”
We want to send the captured image to
three OCR providers and take the result
with the highest confidence value.
‘ ’
D E V L O U N G E
D E V L O U N G E
"Send for OCR": {
"Type": "Parallel",
"Next": "Pick result",
"Branches": [
{
"StartAt": "Prepare1",
"States": {
"Prepare1": {
"Type": "Pass",
"Result": { "inputList": [ "OCR Provider 1" ] },
"Next": "Execute1"
},
"Execute1": {
"Type": "Task",
"Resource": "arn:aws:lambda:ap-southeast-2:123456789012:function:OCR1",
"End": true
}
}
...
}]
},
"Pick Result": { ... }
AWS Step Functions: Parallelism
D E V L O U N G E
“I want to perform a multi-step task and handle errors”
We want to classify images based on
their content, and if the images don’t
contain the right content, we ignore the
uploaded image. We need to distinguish
between the types of errors that can be
generated.
‘
D E V L O U N G E
Amazon
S3
AWS
Lambda
Trigger on
upload
Amazon
Rekognition
D E V L O U N G E
"state.process.Type.Image.Dog":
{
"Type": "Task",
"Resource": "arn:aws:lambda:xxxxx",
"Next": "state.process.Complete",
"Catch": [
{
"ErrorEquals": ["devlounge.exceptions.FileProcessingException"],
"Next": "state.error.FileProcessingException"
},
{
"ErrorEquals": ["States.ALL"],
"Next": "state.error.GeneralException"
}]
}
AWS Step Functions: Error handling
D E V L O U N G E
Throwing errors from NodeJS
D E V L O U N G E
“I want to allow for manual decisions”
We want to classify images based on
their content, and if a confident decision
cannot be made automatically, we want
an operator to be prompted to intervene.
‘
’
D E V L O U N G E
Amazon
S3
AWS
Lambda
Trigger on
upload
Amazon
Rekognition
D E V L O U N G E
Tasks, Activities and Lambda functions
• A task is a unit of work
• Tasks can be implemented by an AWS Lambda function or
an activity which is a placeholder for any compute engine to
implement – on-cloud or off-cloud
• The activity must be resolved by either calling the
SendTaskSuccess or SendTaskFailure APIs
• By implementing a task as an activity, you can implement
manual steps in the state machine. A Lambda function won’t
be called automatically for an activity task.
D E V L O U N G E
"state.process.Type.Unknown":
{
"Type": "Task",
"Resource" : "arn:aws:states:::activity:ManuallyDecide",
"TimeoutSeconds": 3600,
"HeartbeatSeconds": 60,
"Next": ”ContinueTaskAfterManualStep"
}
AWS Step Functions: Activities
If HeartbeatSeconds is provided, the provider must call SendTaskHeartbeat()
within the specified time or the task will fail
D E V L O U N G E
Example: Waiting for a manual activity to complete
• state.process.Type.ManualDecisionRequired is of type activity
• A polling agent periodically checks for activity tasks and obtains
a token to refer to the activity via a call to
stepfunctions::getActivityTask()
• Email sent to an operator with ’manual decision’ links
• When clicked, the links resolve the task as successful or not
• Implemented by a Lambda function behind API Gateway
D E V L O U N G E
Amazon
CloudWatch
AWS
Lambda
AWS Step
Functions
Amazon
SES Amazon API
Gateway
Manual Approval via Email Notification
Scheduled
event getActivityTask()
sendTaskSuccess()
It’s a Dog!
It’s a Cat!
{
output: "”cat"",
taskToken: "xxxx"
}
AWS
Lambda
{
"title": "Numbers to add",
"numbers": [ 3, 4 ]
}
{
"Type": "Task",
"InputPath": "$.numbers",
"Resource": "arn:aws:lambda…"
…
[ 3, 4 ]
Raw input:
State spec:
Task input:
AWS Step Functions: Execution Input State
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.
AWS Step Functions: Execution State Input Processing
{
"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
}
AWS Step Functions: Execution State Result Placement
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.
AWS Step Functions: Execution State Result Placement
D E V L O U N G E
Debugging and traceability
Analyze and debug distributed applications
Calls through AWS SDK automatically captured, or
inject your own custom segments
End-to-End Tracing, cross-service view of requests
made to your application.
AWS X-ray
Annotations
• Key-value pairs with string, number, or Boolean values
• Indexed for use with filter expressions
• Use annotations to record data that you want to use to group traces in the
console, or when calling the GetTraceSummaries API
Metadata
• Key-value pairs that can have values of any type
• Not indexed for use with filter expressions
Custom data: Metadata vs Attributes
D E V L O U N G E
Defining AWS Step Functions using CloudFormation
D E V L O U N G E
• Creating/debugging state machines with ‘Pass’
• Throwing and handling exceptions in AWS Step Functions
• Running state machine workflows in response to events
• Using AWS X-ray to analyse the calls and performance
of Step Functions workflows
• Automating deployment of AWS Step Functions
using AWS CloudFormation
Distributed workflows with AWS Step Functions
D E V L O U N G E
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Adam Larter
Principal Solutions Architect, Developer
Specialist
bit.ly/devlounge-3
E X P R E S S

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Build high performing mobile apps, faster with AWS
Build high performing mobile apps, faster with AWSBuild high performing mobile apps, faster with AWS
Build high performing mobile apps, faster with AWS
 
Working with microservices and Amazon ECS at Airtime
Working with microservices and Amazon ECS at AirtimeWorking with microservices and Amazon ECS at Airtime
Working with microservices and Amazon ECS at Airtime
 
AWS re:Invent 2016: Robots: The Fading Line Between Real and Virtual Worlds (...
AWS re:Invent 2016: Robots: The Fading Line Between Real and Virtual Worlds (...AWS re:Invent 2016: Robots: The Fading Line Between Real and Virtual Worlds (...
AWS re:Invent 2016: Robots: The Fading Line Between Real and Virtual Worlds (...
 
IoT Hack Day: AWS Pop-up Loft Hack Series Sponsored by Intel
IoT Hack Day: AWS Pop-up Loft Hack Series Sponsored by IntelIoT Hack Day: AWS Pop-up Loft Hack Series Sponsored by Intel
IoT Hack Day: AWS Pop-up Loft Hack Series Sponsored by Intel
 
Introduction to AWS IoT
Introduction to AWS IoTIntroduction to AWS IoT
Introduction to AWS IoT
 
AWS Innovate 2016 : Opening Keynote - Glenn Gore
AWS Innovate 2016 :  Opening Keynote - Glenn GoreAWS Innovate 2016 :  Opening Keynote - Glenn Gore
AWS Innovate 2016 : Opening Keynote - Glenn Gore
 
Hands-on with AWS IoT (November 2016)
Hands-on with AWS IoT (November 2016)Hands-on with AWS IoT (November 2016)
Hands-on with AWS IoT (November 2016)
 
How to Connect Your Own Creations with AWS IoT - DevDay Los Angeles 2017
How to Connect Your Own Creations with AWS IoT - DevDay Los Angeles 2017How to Connect Your Own Creations with AWS IoT - DevDay Los Angeles 2017
How to Connect Your Own Creations with AWS IoT - DevDay Los Angeles 2017
 
Connect and Interconnect – The Mesh of Event-Driven Compute and Marvelous Vir...
Connect and Interconnect – The Mesh of Event-Driven Compute and Marvelous Vir...Connect and Interconnect – The Mesh of Event-Driven Compute and Marvelous Vir...
Connect and Interconnect – The Mesh of Event-Driven Compute and Marvelous Vir...
 
AWS re:Invent 2016: Building Complex Serverless Applications (GPST404)
AWS re:Invent 2016: Building Complex Serverless Applications (GPST404)AWS re:Invent 2016: Building Complex Serverless Applications (GPST404)
AWS re:Invent 2016: Building Complex Serverless Applications (GPST404)
 
(GAM401) Build a Serverless Mobile Game w/ Cognito, Lambda & DynamoDB
(GAM401) Build a Serverless Mobile Game w/ Cognito, Lambda & DynamoDB(GAM401) Build a Serverless Mobile Game w/ Cognito, Lambda & DynamoDB
(GAM401) Build a Serverless Mobile Game w/ Cognito, Lambda & DynamoDB
 
如何快速開發與測試App
如何快速開發與測試App如何快速開發與測試App
如何快速開發與測試App
 
Getting Started with AWS IoT
Getting Started with AWS IoTGetting Started with AWS IoT
Getting Started with AWS IoT
 
AWS re:Invent 2016: Building IoT Applications with AWS and Amazon Alexa (HLC304)
AWS re:Invent 2016: Building IoT Applications with AWS and Amazon Alexa (HLC304)AWS re:Invent 2016: Building IoT Applications with AWS and Amazon Alexa (HLC304)
AWS re:Invent 2016: Building IoT Applications with AWS and Amazon Alexa (HLC304)
 
開發語音控制的IoT應用服務
開發語音控制的IoT應用服務開發語音控制的IoT應用服務
開發語音控制的IoT應用服務
 
iNTRODUCTION TO AWS IOT
iNTRODUCTION TO AWS IOTiNTRODUCTION TO AWS IOT
iNTRODUCTION TO AWS IOT
 
AWS March 2016 Webinar Series Getting Started with Serverless Architectures
AWS March 2016 Webinar Series   Getting Started with Serverless ArchitecturesAWS March 2016 Webinar Series   Getting Started with Serverless Architectures
AWS March 2016 Webinar Series Getting Started with Serverless Architectures
 
(MBL311) NEW! AWS IoT: Securely Building, Provisioning, & Using Things
(MBL311) NEW! AWS IoT: Securely Building, Provisioning, & Using Things(MBL311) NEW! AWS IoT: Securely Building, Provisioning, & Using Things
(MBL311) NEW! AWS IoT: Securely Building, Provisioning, & Using Things
 
Programming the Physical World with Device Shadows and Rules Engine
Programming the Physical World with Device Shadows and Rules EngineProgramming the Physical World with Device Shadows and Rules Engine
Programming the Physical World with Device Shadows and Rules Engine
 
Implementing a Serverless IoT Architecture - Pop-up Loft TLV 2017
Implementing a Serverless IoT Architecture - Pop-up Loft TLV 2017Implementing a Serverless IoT Architecture - Pop-up Loft TLV 2017
Implementing a Serverless IoT Architecture - Pop-up Loft TLV 2017
 

Andere mochten auch

Andere mochten auch (20)

Hands on Lab: Deploy .NET Code to AWS from Visual Studio - AWS Online Tech Talks
Hands on Lab: Deploy .NET Code to AWS from Visual Studio - AWS Online Tech TalksHands on Lab: Deploy .NET Code to AWS from Visual Studio - AWS Online Tech Talks
Hands on Lab: Deploy .NET Code to AWS from Visual Studio - AWS Online Tech Talks
 
Building Serverless Websites with Lambda@Edge - AWS Online Tech Talks
Building Serverless Websites with Lambda@Edge - AWS Online Tech TalksBuilding Serverless Websites with Lambda@Edge - AWS Online Tech Talks
Building Serverless Websites with Lambda@Edge - AWS Online Tech Talks
 
Cost Optimisation on AWS
Cost Optimisation on AWSCost Optimisation on AWS
Cost Optimisation on AWS
 
Licensing Windows Workloads on AWS - AWS Online Tech Talks
Licensing Windows Workloads on AWS - AWS Online Tech TalksLicensing Windows Workloads on AWS - AWS Online Tech Talks
Licensing Windows Workloads on AWS - AWS Online Tech Talks
 
Know Before You Go - AWS Online Tech Talks
Know Before You Go - AWS Online Tech TalksKnow Before You Go - AWS Online Tech Talks
Know Before You Go - AWS Online Tech Talks
 
Women in Big Data
Women in Big DataWomen in Big Data
Women in Big Data
 
Disaster Recovery Options with AWS - AWS Online Tech Talks
Disaster Recovery Options with AWS - AWS Online Tech TalksDisaster Recovery Options with AWS - AWS Online Tech Talks
Disaster Recovery Options with AWS - AWS Online Tech Talks
 
Sentiment Analysis Using Apache MXNet and Gluon - AWS Online Tech Talks
Sentiment Analysis Using Apache MXNet and Gluon - AWS Online Tech TalksSentiment Analysis Using Apache MXNet and Gluon - AWS Online Tech Talks
Sentiment Analysis Using Apache MXNet and Gluon - AWS Online Tech Talks
 
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech TalksEssential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
Essential Capabilities of an IoT Cloud Platform - AWS Online Tech Talks
 
9 Security Best Practices
9 Security Best Practices9 Security Best Practices
9 Security Best Practices
 
Bringing Characters to Life with Amazon Polly Text-to-Speech - AWS Online Tec...
Bringing Characters to Life with Amazon Polly Text-to-Speech - AWS Online Tec...Bringing Characters to Life with Amazon Polly Text-to-Speech - AWS Online Tec...
Bringing Characters to Life with Amazon Polly Text-to-Speech - AWS Online Tec...
 
Intro to Amazon AI Services
Intro to Amazon AI ServicesIntro to Amazon AI Services
Intro to Amazon AI Services
 
AWS AI Solutions
AWS AI SolutionsAWS AI Solutions
AWS AI Solutions
 
Module 5: AWS Elasticity and Management Tools - AWSome Day Online Conference
Module 5: AWS Elasticity and Management Tools - AWSome Day Online Conference Module 5: AWS Elasticity and Management Tools - AWSome Day Online Conference
Module 5: AWS Elasticity and Management Tools - AWSome Day Online Conference
 
Visualizing Big Data Insights with Amazon QuickSight
Visualizing Big Data Insights with Amazon QuickSightVisualizing Big Data Insights with Amazon QuickSight
Visualizing Big Data Insights with Amazon QuickSight
 
Analytics on AWS with Amazon Redshift, Amazon QuickSight, and Amazon Machine ...
Analytics on AWS with Amazon Redshift, Amazon QuickSight, and Amazon Machine ...Analytics on AWS with Amazon Redshift, Amazon QuickSight, and Amazon Machine ...
Analytics on AWS with Amazon Redshift, Amazon QuickSight, and Amazon Machine ...
 
Module 3: Security, Identity and Access Management - AWSome Day Online Confer...
Module 3: Security, Identity and Access Management - AWSome Day Online Confer...Module 3: Security, Identity and Access Management - AWSome Day Online Confer...
Module 3: Security, Identity and Access Management - AWSome Day Online Confer...
 
Database Security, Better Audits, Lower Costs
Database Security, Better Audits, Lower CostsDatabase Security, Better Audits, Lower Costs
Database Security, Better Audits, Lower Costs
 
5 Steps to a Secure Hybrid Architecture - Session Sponsored by Palo Alto Netw...
5 Steps to a Secure Hybrid Architecture - Session Sponsored by Palo Alto Netw...5 Steps to a Secure Hybrid Architecture - Session Sponsored by Palo Alto Netw...
5 Steps to a Secure Hybrid Architecture - Session Sponsored by Palo Alto Netw...
 
Extend Enterprise Application-level Security to Your AWS Environment
Extend Enterprise Application-level Security to Your AWS EnvironmentExtend Enterprise Application-level Security to Your AWS Environment
Extend Enterprise Application-level Security to Your AWS Environment
 

Ähnlich wie AWS Step Functions - Dev lounge Express Edition.pdf

Ähnlich wie AWS Step Functions - Dev lounge Express Edition.pdf (20)

Serverless Apps with AWS Step Functions
Serverless Apps with AWS Step FunctionsServerless Apps with AWS Step Functions
Serverless Apps with AWS Step Functions
 
SMC304 Serverless Orchestration with AWS Step Functions
SMC304 Serverless Orchestration with AWS Step FunctionsSMC304 Serverless Orchestration with AWS Step Functions
SMC304 Serverless Orchestration with AWS Step Functions
 
AWS Step Functions을 활용한 서버리스 앱 오케스트레이션
AWS Step Functions을 활용한 서버리스 앱 오케스트레이션AWS Step Functions을 활용한 서버리스 앱 오케스트레이션
AWS Step Functions을 활용한 서버리스 앱 오케스트레이션
 
NEW LAUNCH! Building Distributed Applications with AWS Step Functions
NEW LAUNCH! Building Distributed Applications with AWS Step FunctionsNEW LAUNCH! Building Distributed Applications with AWS Step Functions
NEW LAUNCH! Building Distributed Applications with AWS Step Functions
 
AWS Step Functions 実践
AWS Step Functions 実践AWS Step Functions 実践
AWS Step Functions 実践
 
Building Distributed Applications with AWS Step Functions
Building Distributed Applications with AWS Step FunctionsBuilding Distributed Applications with AWS Step Functions
Building Distributed Applications with AWS Step Functions
 
Decompose the monolith into AWS Step Functions
Decompose the monolith into AWS Step FunctionsDecompose the monolith into AWS Step Functions
Decompose the monolith into AWS Step Functions
 
Announcing AWS Step Functions - December 2016 Monthly Webinar Series
Announcing AWS Step Functions - December 2016 Monthly Webinar SeriesAnnouncing AWS Step Functions - December 2016 Monthly Webinar Series
Announcing AWS Step Functions - December 2016 Monthly Webinar Series
 
Introduction to AWS Step Functions:
Introduction to AWS Step Functions: Introduction to AWS Step Functions:
Introduction to AWS Step Functions:
 
Orchestrating complex workflows with aws step functions
Orchestrating complex workflows with aws step functionsOrchestrating complex workflows with aws step functions
Orchestrating complex workflows with aws step functions
 
Managing Large Numbers of Non trivial ETL pipelines.
Managing Large Numbers of Non trivial ETL pipelines.Managing Large Numbers of Non trivial ETL pipelines.
Managing Large Numbers of Non trivial ETL pipelines.
 
Serverless Orchestration with AWS Step Functions - May 2017 AWS Online Tech T...
Serverless Orchestration with AWS Step Functions - May 2017 AWS Online Tech T...Serverless Orchestration with AWS Step Functions - May 2017 AWS Online Tech T...
Serverless Orchestration with AWS Step Functions - May 2017 AWS Online Tech T...
 
AWS Summit Singapore - Lambda, Step Functions and Datadog: A Symphony
AWS Summit Singapore - Lambda, Step Functions and Datadog: A SymphonyAWS Summit Singapore - Lambda, Step Functions and Datadog: A Symphony
AWS Summit Singapore - Lambda, Step Functions and Datadog: A Symphony
 
NEW LAUNCH! Serverless Apps with AWS Step Functions
NEW LAUNCH! Serverless Apps with AWS Step FunctionsNEW LAUNCH! Serverless Apps with AWS Step Functions
NEW LAUNCH! Serverless Apps with AWS Step Functions
 
Automating EVA Workflows with AWS Step Functions
Automating EVA Workflows with AWS Step FunctionsAutomating EVA Workflows with AWS Step Functions
Automating EVA Workflows with AWS Step Functions
 
ANZ Dev Lounge Session - Feb 2017
ANZ Dev Lounge Session - Feb 2017ANZ Dev Lounge Session - Feb 2017
ANZ Dev Lounge Session - Feb 2017
 
Introduction to AWS Step Functions
Introduction to AWS Step FunctionsIntroduction to AWS Step Functions
Introduction to AWS Step Functions
 
Managing the Continuous Delivery of Code to AWS Lambda
Managing the Continuous Delivery of Code to AWS LambdaManaging the Continuous Delivery of Code to AWS Lambda
Managing the Continuous Delivery of Code to AWS Lambda
 
What’s new in serverless - re:Invent 2020
What’s new in serverless - re:Invent 2020What’s new in serverless - re:Invent 2020
What’s new in serverless - re:Invent 2020
 
BUILDING Serverless apps with MongoDB AtLAS, AWS Lambda and Step Functions
BUILDING Serverless apps with MongoDB AtLAS, AWS Lambda and Step FunctionsBUILDING Serverless apps with MongoDB AtLAS, AWS Lambda and Step Functions
BUILDING Serverless apps with MongoDB AtLAS, AWS Lambda and Step Functions
 

Mehr von Amazon Web Services

Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
Amazon Web Services
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
Amazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
Amazon Web Services
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
Amazon Web Services
 

Mehr von Amazon Web Services (20)

Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
 
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
 
Esegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateEsegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS Fargate
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWS
 
Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot
 
Open banking as a service
Open banking as a serviceOpen banking as a service
Open banking as a service
 
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
 
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
 
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsMicrosoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
 
Computer Vision con AWS
Computer Vision con AWSComputer Vision con AWS
Computer Vision con AWS
 
Database Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareDatabase Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatare
 
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSCrea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e web
 
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareDatabase Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
 
Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
 
Fundraising Essentials
Fundraising EssentialsFundraising Essentials
Fundraising Essentials
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container Service
 

AWS Step Functions - Dev lounge Express Edition.pdf

  • 1. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Adam Larter Principal Solutions Architect, Developer Specialist www.linkedin.com/in/adamlarter/ Real-world development AWS Step Functions and Distributed Complexity E X P R E S S
  • 2. D E V L O U N G E • Distributed complexity and the challenges it introduces • Orchestrating async state machines with AWS Step Functions • Throwing and handling exceptions in AWS Step Functions • Triggering state machine workflows in response to events • Using AWS X-ray to analyse the calls and performance of Step Functions workflows • Lots of code and demos! LEARNING OBJECTIVES
  • 3. D E V L O U N G E Distributed Complexity
  • 4. D E V L O U N G E Serverless microservices AWS LambdaAmazon API Gateway • Highly available • Scalable • Fault tolerant • Cost effective • Secure Microservice Challenges: • Stateless • Discrete / isolated data stores • Distributed / asynchronous
  • 5. D E V L O U N G E Challenge: Transactional Integrity • How do we handle transactional integrity? • Polyglot persistence generally translates into eventual consistency • Asynchronous calls allow non-blocking, but return data (state) needs to be propagated • What about failures and retries? ERROR STATE? ROLLBACK?
  • 6. D E V L O U N G E Challenge: Multi-stage long-running tasks • Tasks that require co-ordination across multiple systems through multiple states • Tasks that may require manual intervention • Tasks that are expected to be long-running and take hours/days/months to resolve • Tasks that are expected to periodically fail and need to be retried as a matter of course
  • 7. D E V L O U N G E Building applications out of distributed functions • “I want to sequence functions” • “I want to run functions in parallel” • “I want to select functions based on input data or current state” • “I want to retry functions with backoff” • “I want try/catch/finally” • “I have code that runs for hours or needs manual intervention” Coordination of asynchronous functions
  • 8. D E V L O U N G E Coordination by function chaining Lambda function A B C D EF G
  • 9. D E V L O U N G E Coordination by function chaining Lambda function A B C D EF G
  • 10. D E V L O U N G E Coordination by database Amazon DynamoDB AWS Lambda function
  • 11. D E V L O U N G E Coordination by queues Amazon SQS AWS Lambda function
  • 12. D E V L O U N G E What would an orchestration solution look like? • Scales out • Doesn’t lose state • Deals with errors/timeouts/retries • Easy to build & operate – declarative, not code-based • Automatable • Auditable • Visible and traceable Coordination must-haves
  • 13. D E V L O U N G E • Fully managed service making it easy to coordinate the components of distributed applications and microservices using visual workflows • You construct your application’s flows as a state machine, a series of steps that together capture the behavior of the application AWS Step Functions
  • 14. D E V L O U N G E AWS Step Functions: State types Parallel Steps Choice State Catch Failure Retry Failure Wait State
  • 15. D E V L O U N G E Example: “Calculator” State Machine
  • 16. D E V L O U N G E Quick anatomy of a state machine • Each state is named uniquely but arbitrarily • StartAt – the entry point • Each state has a type – Choice, Pass, Parallel, Fail, Wait, Task… • Every non-fatal state has a Next state • A fatal state is denoted by End:true or Type:Fail • Task states have a Resource attribute that defines how the state will complete • Tasks can declare a Retry clause based on the type of application-defined error that has occurred
  • 17. D E V L O U N G E “I want to retry functions” We get transient errors from a RESTful service we depend on, once every four or five times we call it. But if we keep retrying, it eventually works. ‘ ’
  • 18. D E V L O U N G E { "Comment": "Call out to a RESTful service", "StartAt": "Call out", "States": { "Call out": { "Type": "Task", "Resource": "arn:aws:lambda:ap-southeast-2:123456789012:function:RESTCall", "Retry": [ { "ErrorEquals": [ ”MyTransientError" ], "MaxAttempts": 10 } ], "End": true } } } AWS Step Functions: Error Handling & Retries
  • 19. D E V L O U N G E “I want to run functions in parallel” We want to send the captured image to three OCR providers and take the result with the highest confidence value. ‘ ’
  • 20. D E V L O U N G E
  • 21. D E V L O U N G E "Send for OCR": { "Type": "Parallel", "Next": "Pick result", "Branches": [ { "StartAt": "Prepare1", "States": { "Prepare1": { "Type": "Pass", "Result": { "inputList": [ "OCR Provider 1" ] }, "Next": "Execute1" }, "Execute1": { "Type": "Task", "Resource": "arn:aws:lambda:ap-southeast-2:123456789012:function:OCR1", "End": true } } ... }] }, "Pick Result": { ... } AWS Step Functions: Parallelism
  • 22. D E V L O U N G E “I want to perform a multi-step task and handle errors” We want to classify images based on their content, and if the images don’t contain the right content, we ignore the uploaded image. We need to distinguish between the types of errors that can be generated. ‘
  • 23. D E V L O U N G E Amazon S3 AWS Lambda Trigger on upload Amazon Rekognition
  • 24. D E V L O U N G E "state.process.Type.Image.Dog": { "Type": "Task", "Resource": "arn:aws:lambda:xxxxx", "Next": "state.process.Complete", "Catch": [ { "ErrorEquals": ["devlounge.exceptions.FileProcessingException"], "Next": "state.error.FileProcessingException" }, { "ErrorEquals": ["States.ALL"], "Next": "state.error.GeneralException" }] } AWS Step Functions: Error handling
  • 25. D E V L O U N G E Throwing errors from NodeJS
  • 26. D E V L O U N G E “I want to allow for manual decisions” We want to classify images based on their content, and if a confident decision cannot be made automatically, we want an operator to be prompted to intervene. ‘ ’
  • 27. D E V L O U N G E Amazon S3 AWS Lambda Trigger on upload Amazon Rekognition
  • 28. D E V L O U N G E Tasks, Activities and Lambda functions • A task is a unit of work • Tasks can be implemented by an AWS Lambda function or an activity which is a placeholder for any compute engine to implement – on-cloud or off-cloud • The activity must be resolved by either calling the SendTaskSuccess or SendTaskFailure APIs • By implementing a task as an activity, you can implement manual steps in the state machine. A Lambda function won’t be called automatically for an activity task.
  • 29. D E V L O U N G E "state.process.Type.Unknown": { "Type": "Task", "Resource" : "arn:aws:states:::activity:ManuallyDecide", "TimeoutSeconds": 3600, "HeartbeatSeconds": 60, "Next": ”ContinueTaskAfterManualStep" } AWS Step Functions: Activities If HeartbeatSeconds is provided, the provider must call SendTaskHeartbeat() within the specified time or the task will fail
  • 30. D E V L O U N G E Example: Waiting for a manual activity to complete • state.process.Type.ManualDecisionRequired is of type activity • A polling agent periodically checks for activity tasks and obtains a token to refer to the activity via a call to stepfunctions::getActivityTask() • Email sent to an operator with ’manual decision’ links • When clicked, the links resolve the task as successful or not • Implemented by a Lambda function behind API Gateway
  • 31. D E V L O U N G E Amazon CloudWatch AWS Lambda AWS Step Functions Amazon SES Amazon API Gateway Manual Approval via Email Notification Scheduled event getActivityTask() sendTaskSuccess() It’s a Dog! It’s a Cat! { output: "”cat"", taskToken: "xxxx" } AWS Lambda
  • 32. { "title": "Numbers to add", "numbers": [ 3, 4 ] } { "Type": "Task", "InputPath": "$.numbers", "Resource": "arn:aws:lambda…" … [ 3, 4 ] Raw input: State spec: Task input: AWS Step Functions: Execution Input State
  • 33. 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. AWS Step Functions: Execution State Input Processing
  • 34. { "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 } AWS Step Functions: Execution State Result Placement
  • 35. 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. AWS Step Functions: Execution State Result Placement
  • 36. D E V L O U N G E Debugging and traceability
  • 37. Analyze and debug distributed applications Calls through AWS SDK automatically captured, or inject your own custom segments End-to-End Tracing, cross-service view of requests made to your application. AWS X-ray
  • 38. Annotations • Key-value pairs with string, number, or Boolean values • Indexed for use with filter expressions • Use annotations to record data that you want to use to group traces in the console, or when calling the GetTraceSummaries API Metadata • Key-value pairs that can have values of any type • Not indexed for use with filter expressions Custom data: Metadata vs Attributes D E V L O U N G E
  • 39. Defining AWS Step Functions using CloudFormation D E V L O U N G E
  • 40. • Creating/debugging state machines with ‘Pass’ • Throwing and handling exceptions in AWS Step Functions • Running state machine workflows in response to events • Using AWS X-ray to analyse the calls and performance of Step Functions workflows • Automating deployment of AWS Step Functions using AWS CloudFormation Distributed workflows with AWS Step Functions D E V L O U N G E
  • 41. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Adam Larter Principal Solutions Architect, Developer Specialist bit.ly/devlounge-3 E X P R E S S