SlideShare uma empresa Scribd logo
1 de 44
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
SRV333 - Designing and
Implementing a Serverless Media
Processing Workflow Using AWS
Step Functions
A n g e l a W a n g
B r i t t a n y D o n c a s t e r
AWS re:INVENT
N o v e m b e r 2 9 , 2 0 1 7
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Part one
Why AWS Step Functions?
Types of states
Workshop overview
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
λλ
λ DBMS
λ
λ
λ
λ
λ
λ λ
λ
λ
Queue
Modern
app
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Modern
app
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions overview
“I want to sequence functions”
“I want to select functions based on data”
I want to run functions in parallel
“I want to retry functions”
“I want to try/catch/finally”
“I want to run code for hours”
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions overview
Visualize in the
console
Define in JSON Monitor
executions
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{
"Comment": "A Hello World Example",
"StartAt": "HelloWorld",
"States": {
"HelloWorld": {
"Type": "Task",
"Resource": "${lambdaArn}",
"End": true
}
}}
AWS::StepFunctions::StateMachine
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Seven state types
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
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What you will build in this workshop
• Multi-step state machine that
leverages several SFN features:
• Lambda task state
• Choice state
• Custom error catching
• Parallel state
• Input/output manipulations
using InputPath and ResultPaths
Task
Choice
Parallel
Fail
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hands-on: Part one (step 0–1C)
• Link to instructions: http://amzn.to/sfn-workshop
What part one will look like when finished:
What you’ll do:
• Run AWS CloudFormation script
• Create state machine using step-easy
tool
• Deploy single-step state machine using
the console
• Test using the console
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Part one review
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ExtractImageMetadata
ImageTypeCheck
TransformMetadata
Rekognition Thumbnail
StoreMetadata
Start
End
Synchronous task
Task: a single unit of work
Synchronous: Lambda
{
"ExtractImageMetadata": {
"Type": "Task",
"Resource": "arn:aws:lambda:mars-ter …”,
…
}
}
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ExtractImageMetadata
ImageTypeCheck
TransformMetadata
Rekognition Thumbnail
StoreMetadata
Start
End
Task: a single unit of work
Asynchronous: “Activity Task”, Polled by workers
{
"ExtractImageMetadata": {
"Type": ”Task",
"Resource": "arn:aws:states:mars-ter …”,
…
}
}
Asynchronous task
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
API actions on activity task
Register Activity task—returns ARN
Poll For task (by ARN)
Report Success
Report Failure
Report Heartbeat
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Part two
Input/output processing
Branching
Custom error handling
Parallel state
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Input/output processing
State [x]
Input
Output
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Input/output processing
State [x]"InputPath" "ResultPath" "OutputPath"
Input
Output
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
InputPath example
{
”s3key”:”apple.png”,
”timestamp”:12324
}
Input
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{
”s3key”:”apple.png”,
”timestamp”:12324
}
"InputPath”:“$”
Input
InputPath example
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{
”s3key”:”apple.png”,
”timestamp”:12324
}
State [x]"InputPath”:“$”
Input
Input received by state x:
{
”s3key”:”apple.png”,
”timestamp”:12324
}
InputPath example
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
"InputPath”:“$.s3key”
{
”s3key”:”apple.png”,
”timestamp”:12324
}
State [x]"InputPath”:“$”
Input
Input received by state x:
{
”s3key”:”apple.png”,
”timestamp”:12324
}
InputPath example
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
State [y]"InputPath”:“$.s3key”
{
”s3key”:”apple.png”,
”timestamp”:12324
}
”apple.png”
State [x]"InputPath”:“$”
Input
Input received by state y:
Input received by state x:
{
”s3key”:”apple.png”,
”timestamp”:12324
}
InputPath example
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{
”s3key”:”apple.png”,
”timestamp”:12324
}
Input
State [x]
State output:
{“type”: “png"}
"InputPath”
: “$.s3key”
”ResultPath”:“$”
ResultPath example
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{
”s3key”:”apple.png”,
”timestamp”:12324
}
Input
State [x]
State output:
{“type”: “png"}
"InputPath”
: “$.s3key”
”ResultPath”:“$”{ ”type”:”png}Output
ResultPath example
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{
”s3key”:”apple.png”,
”timestamp”:12324
}
Input
State [x]
State output:
{“type”: “png"}
"InputPath”
: “$.s3key”
”ResultPath”:“$”{ ”type”:”png}Output
”ResultPath”:“$.metadata”
ResultPath example
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{
”s3key”:”apple.png”,
”timestamp”:12324
}
Input
State [x]
State output:
{“type”: “png"}
"InputPath”
: “$.s3key”
”ResultPath”:“$”{ ”type”:”png}Output
”ResultPath”:“$.metadata”
{
”s3key”:”apple.png”,
”timestamp”:12324,
“metadata”: {
“type”: “png"}
}
Output
ResultPath example
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Branching logic
“ExampleChoiceState": {
"Type": ”Choice",
”Choices": [{
”Variable": ”$.imageformat",
”StringEquals": ”JPG",
”Next": “ParalellProcessing”
}, …
],
”Default": ”NotSupported",
…
}
Choice state
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
“ExampleTaskState": {
"Type": "Task",
"Resource": “<Lambda Arn>",
"Next": "Graceful Exit",
"Retry": [
{
"ErrorEquals": [ “ErrorA" ,”ErrorB”],
"IntervalSeconds": 2,
"MaxAttempts": 2,
"BackoffRate": 1.5
} ,
{
“ErrorEquals” : [ “ErrorC” ],
“Interval Seconds” : 5
],
"Catch": [
{
"ErrorEquals": [ "States.ALL" ],
"Next": "Clean Up" }
]
},
Custom error handling
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Saga pattern to roll back transactions
credit: http://theburningmonk.com/2017/07/applying-the-saga-pattern-with-aws-lambda-and-step-functions/
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
“P": {
"Type": "Parallel",
"Branches": [
{
"StartAt": “P1",
"States": {
“P1": {
"Type": "Task",
"Resource": “<Lambda Arn>",
"End": true } }
},
{
"StartAt": “P2",
"States": {
“P2": {
"Type": "Task",
"Resource": “<Lambda Arn>",
"End": true } }
}
],
"Next": "NextState"
}
Parallel states
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hands-on: Part two (step 1D–3)
• Link to instructions: http://amzn.to/sfn-workshop
What part two will look like when finished:
What you’ll do:
• Add ResultPath
• Add choice state
• Add custom error handling
• Add parallel state
• Test using the console
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Demo part two
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Part two review
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Part three
Other architecture patterns
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Video on Demand—AWS Quick Start
https://docs.aws.amazon.com/solutions/latest/video-on-demand
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Use activity task for manual approval
Step Functions
Poll:
taskToken
Amazon
SES
Poller
Approver
Send success:
taskToken
API
Gateway
https://aws.amazon.com/blogs/compute/implementing-serverless-manual-
approval-steps-in-aws-step-functions-and-amazon-api-gateway/
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
while:
sleep (30)
if status=done:
break
Use Wait + Choice to wait for batch job/async
APIs
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Integrate with other AWS services
• Create state machines and activities with AWS CloudFormation
• Call AWS Step Functions with Amazon API Gateway
• Start state machines in response to events, or on a schedule, with Amazon
CloudWatch Events
• Monitor state machine executions with Amazon CloudWatch
• Log API calls with AWS CloudTrail
• Start state machine using AWS Lambda
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hands-on: Part three (step 3–end)
• Link to instructions: http://amzn.to/sfn-workshop
What you’ll do:
• Add a final task state to persist the metadata
• Configure the trigger for the state machine
• Deploy a test web application and test
Optional bonus tasks: (if finished early and want to keep going)
Add in additional error handling/retry logic
Add a manual approval task if inappropriate content is found
A state machine to clean up when images are deleted
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Discussion
• Other ideas for extending the state machine?
• Ideas on how you can use Step Functions
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Q&A
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Learn more
Thu. Nov. 30
2:30–5:00
ARC326: Create a Serverless Image Processing Platform
Thu. Nov. 30
5:30–6:30
SRV306: State Machines in the Wild! How Customers use AWS Step Functions
Meet experts at the Serverless Kiosk in the Expo
Resources: https://aws.amazon.com/step-functions/reinvent
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What are you building? #stepfunctions
Serverless image recognition and processing backendEBS snapshot management
https://console.aws.amazon.com/states/
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
THANK YOU!
h t t p s : / / a w s . a m a z o n . c o m / s t e p - f u n c t i o n s / g e t t i n g - s t a r t e d

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Introducing Amazon EKS
Introducing Amazon EKSIntroducing Amazon EKS
Introducing Amazon EKS
 
SID301_Using AWS Lambda as a Security Team
SID301_Using AWS Lambda as a Security TeamSID301_Using AWS Lambda as a Security Team
SID301_Using AWS Lambda as a Security Team
 
NEW LAUNCH! AWS IoT Device Management - IOT330 - re:Invent 2017
NEW LAUNCH! AWS IoT Device Management - IOT330 - re:Invent 2017NEW LAUNCH! AWS IoT Device Management - IOT330 - re:Invent 2017
NEW LAUNCH! AWS IoT Device Management - IOT330 - re:Invent 2017
 
Application Performance Management on AWS
Application Performance Management on AWSApplication Performance Management on AWS
Application Performance Management on AWS
 
Improving Microservice and Serverless Observability with Monitoring Data - SR...
Improving Microservice and Serverless Observability with Monitoring Data - SR...Improving Microservice and Serverless Observability with Monitoring Data - SR...
Improving Microservice and Serverless Observability with Monitoring Data - SR...
 
CON319_Interstella GTC CICD for Containers on AWS
CON319_Interstella GTC CICD for Containers on AWSCON319_Interstella GTC CICD for Containers on AWS
CON319_Interstella GTC CICD for Containers on AWS
 
Deep Dive: AWS Direct Connect and VPNs - NET403 - re:Invent 2017
Deep Dive: AWS Direct Connect and VPNs - NET403 - re:Invent 2017Deep Dive: AWS Direct Connect and VPNs - NET403 - re:Invent 2017
Deep Dive: AWS Direct Connect and VPNs - NET403 - re:Invent 2017
 
SRV310_Designing Microservices with Serverless
SRV310_Designing Microservices with ServerlessSRV310_Designing Microservices with Serverless
SRV310_Designing Microservices with Serverless
 
Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017
Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017
Building CI/CD Pipelines for Serverless Applications - SRV302 - re:Invent 2017
 
IOT308-One Message to a Million Things Done in 60 seconds with AWS IoT
IOT308-One Message to a Million Things Done in 60 seconds with AWS IoTIOT308-One Message to a Million Things Done in 60 seconds with AWS IoT
IOT308-One Message to a Million Things Done in 60 seconds with AWS IoT
 
CON318_Interstella 8888 Monolith to Microservices with Amazon ECS
CON318_Interstella 8888 Monolith to Microservices with Amazon ECSCON318_Interstella 8888 Monolith to Microservices with Amazon ECS
CON318_Interstella 8888 Monolith to Microservices with Amazon ECS
 
SRV332_Building Serverless Real-Time Data Processing (Now with Unicorns!).pdf
SRV332_Building Serverless Real-Time Data Processing (Now with Unicorns!).pdfSRV332_Building Serverless Real-Time Data Processing (Now with Unicorns!).pdf
SRV332_Building Serverless Real-Time Data Processing (Now with Unicorns!).pdf
 
ALX306_Build a Game Skill for Echo Buttons!
ALX306_Build a Game Skill for Echo Buttons!ALX306_Build a Game Skill for Echo Buttons!
ALX306_Build a Game Skill for Echo Buttons!
 
Serverless Architectural Patterns
Serverless Architectural PatternsServerless Architectural Patterns
Serverless Architectural Patterns
 
ARC325_Managing Multiple AWS Accounts at Scale
ARC325_Managing Multiple AWS Accounts at ScaleARC325_Managing Multiple AWS Accounts at Scale
ARC325_Managing Multiple AWS Accounts at Scale
 
NEW LAUNCH! Gain Operational Insights and Take Action on AWS Resources with A...
NEW LAUNCH! Gain Operational Insights and Take Action on AWS Resources with A...NEW LAUNCH! Gain Operational Insights and Take Action on AWS Resources with A...
NEW LAUNCH! Gain Operational Insights and Take Action on AWS Resources with A...
 
SID402_An AWS Security Odyssey
SID402_An AWS Security OdysseySID402_An AWS Security Odyssey
SID402_An AWS Security Odyssey
 
Best Practices for using AWS Lambda with RDS-RDBMS Solutions (SRV320)
Best Practices for using AWS Lambda with RDS-RDBMS Solutions (SRV320)Best Practices for using AWS Lambda with RDS-RDBMS Solutions (SRV320)
Best Practices for using AWS Lambda with RDS-RDBMS Solutions (SRV320)
 
SecOps 2021 Today: Using AWS Services to Deliver SecOps - SID304 - re:Invent ...
SecOps 2021 Today: Using AWS Services to Deliver SecOps - SID304 - re:Invent ...SecOps 2021 Today: Using AWS Services to Deliver SecOps - SID304 - re:Invent ...
SecOps 2021 Today: Using AWS Services to Deliver SecOps - SID304 - re:Invent ...
 
SID302_Force Multiply Your Security Team with Automation and Alexa
SID302_Force Multiply Your Security Team with Automation and AlexaSID302_Force Multiply Your Security Team with Automation and Alexa
SID302_Force Multiply Your Security Team with Automation and Alexa
 

Semelhante a Designing and Implementing a Serverless Media Processing Workflow Using AWS Step Functions - SRV333 - re:Invent 2017

The Best Practices and Hard Lessons Learned of Serverless Applications - AWS ...
The Best Practices and Hard Lessons Learned of Serverless Applications - AWS ...The Best Practices and Hard Lessons Learned of Serverless Applications - AWS ...
The Best Practices and Hard Lessons Learned of Serverless Applications - AWS ...
Amazon Web Services
 

Semelhante a Designing and Implementing a Serverless Media Processing Workflow Using AWS Step Functions - SRV333 - re:Invent 2017 (20)

Design and Implement a Serverless Media-Processing Workflow - SRV328 - Atlant...
Design and Implement a Serverless Media-Processing Workflow - SRV328 - Atlant...Design and Implement a Serverless Media-Processing Workflow - SRV328 - Atlant...
Design and Implement a Serverless Media-Processing Workflow - SRV328 - Atlant...
 
Design and Implement a Serverless Media-Processing Workflow
Design and Implement a Serverless Media-Processing Workflow Design and Implement a Serverless Media-Processing Workflow
Design and Implement a Serverless Media-Processing Workflow
 
SRV328 Designing and Implementing a Serverless Media-Processing Workflow
SRV328 Designing and Implementing a Serverless Media-Processing WorkflowSRV328 Designing and Implementing a Serverless Media-Processing Workflow
SRV328 Designing and Implementing a Serverless Media-Processing Workflow
 
Advanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step FunctionsAdvanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step Functions
 
Advanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step FunctionsAdvanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step Functions
 
Building Advanced Serverless Applications
Building Advanced Serverless ApplicationsBuilding Advanced Serverless Applications
Building Advanced Serverless Applications
 
使用 AWS Step Functions 靈活調度 AWS Lambda (Level:200)
使用 AWS Step Functions 靈活調度 AWS Lambda (Level:200)使用 AWS Step Functions 靈活調度 AWS Lambda (Level:200)
使用 AWS Step Functions 靈活調度 AWS Lambda (Level:200)
 
Serverless Apps with AWS Step Functions
Serverless Apps with AWS Step FunctionsServerless Apps with AWS Step Functions
Serverless Apps with AWS Step Functions
 
Serverless Developer Experience I AWS Dev Day 2018
Serverless Developer Experience I AWS Dev Day 2018Serverless Developer Experience I AWS Dev Day 2018
Serverless Developer Experience I AWS Dev Day 2018
 
The Best Practices and Hard Lessons Learned of Serverless Applications - AWS ...
The Best Practices and Hard Lessons Learned of Serverless Applications - AWS ...The Best Practices and Hard Lessons Learned of Serverless Applications - AWS ...
The Best Practices and Hard Lessons Learned of Serverless Applications - AWS ...
 
AWS Startup Day - Boston 2018 - The Best Practices and Hard Lessons Learned o...
AWS Startup Day - Boston 2018 - The Best Practices and Hard Lessons Learned o...AWS Startup Day - Boston 2018 - The Best Practices and Hard Lessons Learned o...
AWS Startup Day - Boston 2018 - The Best Practices and Hard Lessons Learned o...
 
AWS18 Startup Day Toronto- The Best Practices and Hard Lessons Learned of Ser...
AWS18 Startup Day Toronto- The Best Practices and Hard Lessons Learned of Ser...AWS18 Startup Day Toronto- The Best Practices and Hard Lessons Learned of Ser...
AWS18 Startup Day Toronto- The Best Practices and Hard Lessons Learned of Ser...
 
Building Advanced Serverless Workflows with AWS Step Functions | AWS Floor28
Building Advanced Serverless Workflows with AWS Step Functions | AWS Floor28Building Advanced Serverless Workflows with AWS Step Functions | AWS Floor28
Building Advanced Serverless Workflows with AWS Step Functions | AWS Floor28
 
Best Practices for Orchestrating AWS Lambda Workloads - SRV335 - re:Invent 2017
Best Practices for Orchestrating AWS Lambda Workloads - SRV335 - re:Invent 2017Best Practices for Orchestrating AWS Lambda Workloads - SRV335 - re:Invent 2017
Best Practices for Orchestrating AWS Lambda Workloads - SRV335 - re:Invent 2017
 
Serverless Development Deep Dive
Serverless Development Deep DiveServerless Development Deep Dive
Serverless Development Deep Dive
 
Best Practices and Hard Lessons of Serverless- AWS Startup Day Toronto- Diego...
Best Practices and Hard Lessons of Serverless- AWS Startup Day Toronto- Diego...Best Practices and Hard Lessons of Serverless- AWS Startup Day Toronto- Diego...
Best Practices and Hard Lessons of Serverless- AWS Startup Day Toronto- Diego...
 
Automate your Amazon SageMaker Workflows (July 2019)
Automate your Amazon SageMaker Workflows (July 2019)Automate your Amazon SageMaker Workflows (July 2019)
Automate your Amazon SageMaker Workflows (July 2019)
 
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
 
20190522 AWS Black Belt Online Seminar AWS Step Functions
20190522 AWS Black Belt Online Seminar AWS Step Functions20190522 AWS Black Belt Online Seminar AWS Step Functions
20190522 AWS Black Belt Online Seminar AWS Step Functions
 
Real Time and Offline Applications with GraphQL
Real Time and Offline Applications with GraphQLReal Time and Offline Applications with GraphQL
Real Time and Offline Applications with GraphQL
 

Mais de 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
 

Mais de 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
 

Designing and Implementing a Serverless Media Processing Workflow Using AWS Step Functions - SRV333 - re:Invent 2017

  • 1. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. SRV333 - Designing and Implementing a Serverless Media Processing Workflow Using AWS Step Functions A n g e l a W a n g B r i t t a n y D o n c a s t e r AWS re:INVENT N o v e m b e r 2 9 , 2 0 1 7
  • 2. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Part one Why AWS Step Functions? Types of states Workshop overview
  • 3. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. λλ λ DBMS λ λ λ λ λ λ λ λ λ Queue Modern app
  • 4. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Modern app
  • 5. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions overview “I want to sequence functions” “I want to select functions based on data” I want to run functions in parallel “I want to retry functions” “I want to try/catch/finally” “I want to run code for hours”
  • 6. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions overview Visualize in the console Define in JSON Monitor executions
  • 7. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. { "Comment": "A Hello World Example", "StartAt": "HelloWorld", "States": { "HelloWorld": { "Type": "Task", "Resource": "${lambdaArn}", "End": true } }} AWS::StepFunctions::StateMachine
  • 8. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Seven state types 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
  • 9. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. What you will build in this workshop • Multi-step state machine that leverages several SFN features: • Lambda task state • Choice state • Custom error catching • Parallel state • Input/output manipulations using InputPath and ResultPaths Task Choice Parallel Fail
  • 10. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Hands-on: Part one (step 0–1C) • Link to instructions: http://amzn.to/sfn-workshop What part one will look like when finished: What you’ll do: • Run AWS CloudFormation script • Create state machine using step-easy tool • Deploy single-step state machine using the console • Test using the console
  • 11. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Part one review
  • 12. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. ExtractImageMetadata ImageTypeCheck TransformMetadata Rekognition Thumbnail StoreMetadata Start End Synchronous task Task: a single unit of work Synchronous: Lambda { "ExtractImageMetadata": { "Type": "Task", "Resource": "arn:aws:lambda:mars-ter …”, … } }
  • 13. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. ExtractImageMetadata ImageTypeCheck TransformMetadata Rekognition Thumbnail StoreMetadata Start End Task: a single unit of work Asynchronous: “Activity Task”, Polled by workers { "ExtractImageMetadata": { "Type": ”Task", "Resource": "arn:aws:states:mars-ter …”, … } } Asynchronous task
  • 14. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. API actions on activity task Register Activity task—returns ARN Poll For task (by ARN) Report Success Report Failure Report Heartbeat
  • 15. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Part two Input/output processing Branching Custom error handling Parallel state
  • 16. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Input/output processing State [x] Input Output
  • 17. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Input/output processing State [x]"InputPath" "ResultPath" "OutputPath" Input Output
  • 18. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. InputPath example { ”s3key”:”apple.png”, ”timestamp”:12324 } Input
  • 19. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. { ”s3key”:”apple.png”, ”timestamp”:12324 } "InputPath”:“$” Input InputPath example
  • 20. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. { ”s3key”:”apple.png”, ”timestamp”:12324 } State [x]"InputPath”:“$” Input Input received by state x: { ”s3key”:”apple.png”, ”timestamp”:12324 } InputPath example
  • 21. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. "InputPath”:“$.s3key” { ”s3key”:”apple.png”, ”timestamp”:12324 } State [x]"InputPath”:“$” Input Input received by state x: { ”s3key”:”apple.png”, ”timestamp”:12324 } InputPath example
  • 22. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. State [y]"InputPath”:“$.s3key” { ”s3key”:”apple.png”, ”timestamp”:12324 } ”apple.png” State [x]"InputPath”:“$” Input Input received by state y: Input received by state x: { ”s3key”:”apple.png”, ”timestamp”:12324 } InputPath example
  • 23. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. { ”s3key”:”apple.png”, ”timestamp”:12324 } Input State [x] State output: {“type”: “png"} "InputPath” : “$.s3key” ”ResultPath”:“$” ResultPath example
  • 24. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. { ”s3key”:”apple.png”, ”timestamp”:12324 } Input State [x] State output: {“type”: “png"} "InputPath” : “$.s3key” ”ResultPath”:“$”{ ”type”:”png}Output ResultPath example
  • 25. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. { ”s3key”:”apple.png”, ”timestamp”:12324 } Input State [x] State output: {“type”: “png"} "InputPath” : “$.s3key” ”ResultPath”:“$”{ ”type”:”png}Output ”ResultPath”:“$.metadata” ResultPath example
  • 26. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. { ”s3key”:”apple.png”, ”timestamp”:12324 } Input State [x] State output: {“type”: “png"} "InputPath” : “$.s3key” ”ResultPath”:“$”{ ”type”:”png}Output ”ResultPath”:“$.metadata” { ”s3key”:”apple.png”, ”timestamp”:12324, “metadata”: { “type”: “png"} } Output ResultPath example
  • 27. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Branching logic “ExampleChoiceState": { "Type": ”Choice", ”Choices": [{ ”Variable": ”$.imageformat", ”StringEquals": ”JPG", ”Next": “ParalellProcessing” }, … ], ”Default": ”NotSupported", … } Choice state
  • 28. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. “ExampleTaskState": { "Type": "Task", "Resource": “<Lambda Arn>", "Next": "Graceful Exit", "Retry": [ { "ErrorEquals": [ “ErrorA" ,”ErrorB”], "IntervalSeconds": 2, "MaxAttempts": 2, "BackoffRate": 1.5 } , { “ErrorEquals” : [ “ErrorC” ], “Interval Seconds” : 5 ], "Catch": [ { "ErrorEquals": [ "States.ALL" ], "Next": "Clean Up" } ] }, Custom error handling
  • 29. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Saga pattern to roll back transactions credit: http://theburningmonk.com/2017/07/applying-the-saga-pattern-with-aws-lambda-and-step-functions/
  • 30. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. “P": { "Type": "Parallel", "Branches": [ { "StartAt": “P1", "States": { “P1": { "Type": "Task", "Resource": “<Lambda Arn>", "End": true } } }, { "StartAt": “P2", "States": { “P2": { "Type": "Task", "Resource": “<Lambda Arn>", "End": true } } } ], "Next": "NextState" } Parallel states
  • 31. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Hands-on: Part two (step 1D–3) • Link to instructions: http://amzn.to/sfn-workshop What part two will look like when finished: What you’ll do: • Add ResultPath • Add choice state • Add custom error handling • Add parallel state • Test using the console
  • 32. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Demo part two
  • 33. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Part two review
  • 34. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Part three Other architecture patterns
  • 35. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Video on Demand—AWS Quick Start https://docs.aws.amazon.com/solutions/latest/video-on-demand
  • 36. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Use activity task for manual approval Step Functions Poll: taskToken Amazon SES Poller Approver Send success: taskToken API Gateway https://aws.amazon.com/blogs/compute/implementing-serverless-manual- approval-steps-in-aws-step-functions-and-amazon-api-gateway/
  • 37. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. while: sleep (30) if status=done: break Use Wait + Choice to wait for batch job/async APIs
  • 38. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Integrate with other AWS services • Create state machines and activities with AWS CloudFormation • Call AWS Step Functions with Amazon API Gateway • Start state machines in response to events, or on a schedule, with Amazon CloudWatch Events • Monitor state machine executions with Amazon CloudWatch • Log API calls with AWS CloudTrail • Start state machine using AWS Lambda
  • 39. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Hands-on: Part three (step 3–end) • Link to instructions: http://amzn.to/sfn-workshop What you’ll do: • Add a final task state to persist the metadata • Configure the trigger for the state machine • Deploy a test web application and test Optional bonus tasks: (if finished early and want to keep going) Add in additional error handling/retry logic Add a manual approval task if inappropriate content is found A state machine to clean up when images are deleted
  • 40. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Discussion • Other ideas for extending the state machine? • Ideas on how you can use Step Functions
  • 41. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Q&A
  • 42. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Learn more Thu. Nov. 30 2:30–5:00 ARC326: Create a Serverless Image Processing Platform Thu. Nov. 30 5:30–6:30 SRV306: State Machines in the Wild! How Customers use AWS Step Functions Meet experts at the Serverless Kiosk in the Expo Resources: https://aws.amazon.com/step-functions/reinvent
  • 43. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. What are you building? #stepfunctions Serverless image recognition and processing backendEBS snapshot management https://console.aws.amazon.com/states/
  • 44. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. THANK YOU! h t t p s : / / a w s . a m a z o n . c o m / s t e p - f u n c t i o n s / g e t t i n g - s t a r t e d