SlideShare uma empresa Scribd logo
1 de 45
Baixar para ler offline
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Paul Maddox
Developer Technologies, AWS
April 2018
Building Advanced Serverless Applications
with AWS Step Functions (starting 15:45)
Twitter: @paulmaddox
Email: pmaddox@amazon.com
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
About me
Paul Maddox
Developer Technologies
Amazon Web Services
• 16 years of dev, SRE, and systems architecture background
• 7 of 7 AWS certifications
• Developer: Go/Java/C/Node
• Creator of AWS SAM Local
Twitter: @paulmaddox
Email: pmaddox@amazon.com
@paulmaddox
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
"Serverless requires me to
develop in a completely different
way"
Myth Busting Time…
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
"Serverless isn't for
advanced applications"
Myth Busting Time…
λλ
λ
DBMS
λ
λ
λ
λ
λ
λ λ
λ
λ
Queue
Modern
serverless
app
Modern
serverless
app
"I want to sequence functions"
"I want to select functions based on data"
"I want to retry functions"
"I want try/catch/finally"
Functions into apps
"I have code that runs for hours"
"I want to run functions in parallel"
Coordination must-haves
• Scales out
• Doesn’t lose state
• Deals with errors/timeouts
• Easy to build & operate
• Auditable
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
“Any sufficiently complicated model class contains an
ad-hoc, informally-specified, bug-ridden, slow
implementation of half of a state machine.”
http://raganwald.com/2018/02/23/forde.html
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
The problem is that you almost never create an object
fully formed with all the behaviour it is ever going to
need, rather you build it up over time.
https://www.skorks.com/2011/09/why-developers-never-use-state-machines/
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Application Lifecycle in AWS Step Functions
Visualize in the
Console
Define in JSON Monitor
Executions
Define in JSON and Then Visualize in the Console
{
"Comment": "Hello World Example",
"StartAt" : "HelloWorld",
"States" : {
"HelloWorld" : {
"Type" : "Task",
"Resource" : "${lambdaArn}",
"End" : true
}
}
}
Execute One or One Million
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Start
End
HelloWorld
Maximum Execution Time
AWS Lambda
Functions
5 minutes
AWS Step Functions
State Machines
1 year
Monitor Executions from the Console
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.
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
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
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.
O
pen
Source
A
pache
License
https://states-language.net/spec.html
© 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
Build Visual Workflows from State Types
Task
Choice
Fail
Parallel
Serverless Human Approval Tasks
https://aws.amazon.com/blogs/compute/
implementing-serverless-manual-approval-steps-in-aws-step-functions-and-amazon-api-gateway/
Image Recognition and Processing Backend
Task
Choice
Fail
Parallel
https://github.com/awslabs/lambda-refarch-imagerecognition
Amazon EBS Snapshot Management
State Machine State Machine
create-snapshot
complete event
copy-snapshot
complete event
Primary Region DR Region
Parallel State
Choice
Tag Snapshot
Count Snapshots
CopyToDRRegion
Success
State
Delete
Snapshots
Choice
Tag SnapshotCopy
Count Snapshots
Pass State
Delete
Snapshots
Notification
Topic
Errors Sent
to SNS
Notification
Topic
Errors Sent
to SNS
https://github.com/awslabs/aws-step-functions-ebs-snapshot-mgmt
1. Tag
2. Count
3. Copy to DR region
4. Delete Expired
Whenever a new EBS
snapshot completes:
State Machines
invoked by Amazon
CloudWatch Events
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Who's using this in production?
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Vending Pass problem
1. Thirsty consumer presents
card, can buy a drink with
Vending Pass or debit
2. But mobile wallet display can
get out of sync under certain
conditions
3.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Vending Pass problem
• Use Step Functions to co-
ordinate and verify state
• Cheap and simple!
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
• Transcode 350 clips/day into
14 formats, fast
• It’s all done with FFmpeg. The
processing time is just about
100% of the video length
• Aargh!
Video processing problem
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
• Derive keyframe locations
within the source
• Split the source at the
keyframes
• Process segments (typically
0.5 sec per) in parallel
• Concatenate segments
• Elapsed time: ~20 min down
to ~2 minutes
Video processing solution
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Details
How to get from Lambda to Amazon S3:
ffmpeg -f concat –safe 0 -I filelist.ffcat –c copy pipe:0 |
aws s3 cp – s3://output-bucket/output-file.mp4
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Details
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Let’s peek at the code!
"Init": {
"Type": "Pass",
"ResultPath": "$.operation",
"Result": "prepare-split",
"Next": "PrepareSplit"
},
"PrepareSplit": {
"Type": "Task",
"Resource": "arn:…:ffmpeg-18HFP9FXFL6P",
"Next": "SplitPrepared"
},
"SplitPrepared": {
"Type": "Pass",
"ResultPath": "$.operation",
"Result": "perform-split",
"Next": "PerformSplit"
},
"PerformSplit": {
"Type": "Task",
"Resource": "arn:…:ffmpeg-18HFP9FXFL6P",
"Next": "SplitPerformed"
},
"SplitPerformed": {
"Type": "Pass",
"ResultPath": "$.operation",
"Result": "poll-results",
"Next": "PreparePoll"
},
"PreparePoll": {
"Type": "Pass",
"ResultPath": "$.pollstatus",
"Result": "Submitted",
"Next": "WaitForResults"
}
Hmm…the same function,
throughout
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Let’s peek at the code!
"WaitForResults": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.pollstatus",
"StringEquals": "Complete",
"Next": "SegmentsCompleteState"
},
{
"Variable": "$.pollstatus",
"StringEquals": "Progressing",
"Next": "loop_wait_using_seconds"
},
{
"Variable": "$.pollstatus",
"StringEquals": "Submitted",
"Next": "loop_wait_using_seconds"
}
]
}
"loop_wait_using_seconds": {
"Type": "Wait",
"Seconds": 3,
"Next": "loop"
},
"loop": {
"Type": "Task",
"Resource": "arn:…:ffmpeg-18HFP9FXFL6P",
"Next": "WaitForResults"
},
"SegmentsCompleteState": {
"Type": "Pass",
"ResultPath": "$.operation",
"Result": "concat",
"Next": "CompleteState"
},
"CompleteState": {
"Type": "Task",
"Resource": " arn:…:ffmpeg-18HFP9FXFL6P",
"End": true
}
Counts the segments,
sets $.pollstatus
Stitches segments together
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Takeaways
Use Amazon S3
data events to
trigger parallel
Lambda
processing: win
Use Amazon S3
URLs to stream
video to
Lambda: win
Scaling to 1,000
Lambdas, rather
than 1,000 EC2
instances: win
Process video
segments in
parallel: win
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
1. Sometimes Lambda is best, sometimes ECS
2. Previously, all tied together with
pub/sub and
procedural code
3. Aargh!
Media transcoding problem
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
1. Use state machines to pick
execution engine
2. Use CloudWatch Events for
messaging and triggering
Step Functions
Media transcoding solution
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Let’s peek at the code!
"Encoder Decider": {
"Type": "Choice",
"Default": "Run ECS Encoder",
"Choices": [
{
"Next": "Run Lambda Encoder",
"And": [
{
"Variable": "$.asset.size",
"NumericLessThanEquals": 2000000000
},
{
"Variable": "$.asset.duration_ms",
"NumericLessThanEquals": 10000
}
]
}
]
}
Hmm…maybe "Default"
should have been called "Else"
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Let’s peek at the code!
"Run ECS Encoder": {
"Type": "Task",
"Resource": "arn:…SubmitECSTask",
"Retry": [
{
"ErrorEquals": [
"NoResourceInCluster"
],
"IntervalSeconds": 5,
"MaxAttempts": 720,
"BackoffRate": 1.0
}
],
"ResultPath": "$.task",
"Next": "Wait X Seconds"
}
Hmm…every 5 seconds,
for an hour?!
"Wait X Seconds": {
"Type": "Wait",
"SecondsPath": "$.task.wait_time",
"Next": "Get ECS Task Status"
},
"Get ECS Task Status": {
"Type": "Task",
"Resource": "arn:…ECSTaskStatus",
"Next": "ECS Task Complete?",
"ResultPath": "$.task.status"
}
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Let’s peek at the code!
"ECS Task Complete?": {
"Type": "Choice",
"Choices": [
{
"And": [
{
"Variable": "$.task.status",
"StringEquals": "FAILED"
},
{
"Variable": "$.task.attempt",
"NumericGreaterThanEquals": 3
}
],
"Next": "Fire Failed Event"
},
{
"Variable": "$.task.status",
"StringEquals": "FAILED",
"Next": "Run ECS Encoder"
},
{
"Variable": "$.task.status",
"StringEquals": "SUCCEEDED",
"Next": "Fire Successful Event"
}
],
"Default": "Wait X Seconds"
},
"Fire Successful Event": {
"Type": "Task",
"Resource": "aws:…SendSuccessfulEvent",
"End": true
},
"Fire Failed Event": {
"Type": "Task",
"Resource": "aws:…SendFailedEvent",
"End": true
}
These fire
CloudWatch
Events
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Takeaways
Passing a
correlation ID
through a complex
serverless app: win
SAM to make
code changes
auditable: win
Code Pipeline
for CI/CD: winCloudWatch
Events pattern
matching: win
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
More state machines
Image Recognition and Processing BackendEBS Snapshot Management
https://aws.amazon.com/step-functions/getting-started
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What are you building? #stepfunctions
https://console.aws.amazon.com/states/
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Thank you!
Twitter: @paulmaddox
Email: pmaddox@amazon.com@paulmaddox

Mais conteúdo relacionado

Mais procurados

Serverless Applications with AWS SAM
Serverless Applications with AWS SAMServerless Applications with AWS SAM
Serverless Applications with AWS SAMChris Munns
 
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...Chris Munns
 
Building CICD Pipelines for Serverless Applications
Building CICD Pipelines for Serverless ApplicationsBuilding CICD Pipelines for Serverless Applications
Building CICD Pipelines for Serverless ApplicationsAmazon Web Services
 
Building APIs with Amazon API Gateway: re:Invent 2018 Recap at the AWS Loft -...
Building APIs with Amazon API Gateway: re:Invent 2018 Recap at the AWS Loft -...Building APIs with Amazon API Gateway: re:Invent 2018 Recap at the AWS Loft -...
Building APIs with Amazon API Gateway: re:Invent 2018 Recap at the AWS Loft -...Amazon Web Services
 
Deep Dive on Serverless Application Development NY Loft
Deep Dive on Serverless Application Development NY LoftDeep Dive on Serverless Application Development NY Loft
Deep Dive on Serverless Application Development NY LoftAmazon Web Services
 
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 Floor28Amazon Web Services
 
Unlocking Agility with the AWS Serverless Application Model (SAM)
Unlocking Agility with the AWS Serverless Application Model (SAM)Unlocking Agility with the AWS Serverless Application Model (SAM)
Unlocking Agility with the AWS Serverless Application Model (SAM)Amazon Web Services
 
Getting Started with AWS Lambda Serverless Computing
Getting Started with AWS Lambda Serverless ComputingGetting Started with AWS Lambda Serverless Computing
Getting Started with AWS Lambda Serverless ComputingAmazon Web Services
 
Introduction to Serverless computing and AWS Lambda - Floor28
Introduction to Serverless computing and AWS Lambda - Floor28Introduction to Serverless computing and AWS Lambda - Floor28
Introduction to Serverless computing and AWS Lambda - Floor28Boaz Ziniman
 
Advanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step FunctionsAdvanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step FunctionsAmazon Web Services
 
Overview of Serverless Application Deployment Patterns - AWS Online Tech Talks
Overview of Serverless Application Deployment Patterns - AWS Online Tech TalksOverview of Serverless Application Deployment Patterns - AWS Online Tech Talks
Overview of Serverless Application Deployment Patterns - AWS Online Tech TalksAmazon Web Services
 
Getting Started with AWS Lambda & Serverless Computing
Getting Started with AWS Lambda & Serverless ComputingGetting Started with AWS Lambda & Serverless Computing
Getting Started with AWS Lambda & Serverless ComputingAmazon Web Services
 
Local Testing and Deployment Best Practices for Serverless Applications - AWS...
Local Testing and Deployment Best Practices for Serverless Applications - AWS...Local Testing and Deployment Best Practices for Serverless Applications - AWS...
Local Testing and Deployment Best Practices for Serverless Applications - AWS...Amazon Web Services
 
AWS Lambda Layers, the Runtime API, & Nested Applications: re:Invent 2018 Rec...
AWS Lambda Layers, the Runtime API, & Nested Applications: re:Invent 2018 Rec...AWS Lambda Layers, the Runtime API, & Nested Applications: re:Invent 2018 Rec...
AWS Lambda Layers, the Runtime API, & Nested Applications: re:Invent 2018 Rec...Amazon Web Services
 
Advanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step FunctionsAdvanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step FunctionsAmazon Web Services
 
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...Chris Munns
 
Serverless Architecture Patterns
Serverless Architecture PatternsServerless Architecture Patterns
Serverless Architecture PatternsAmazon Web Services
 
Introduction to AWS Lambda and Serverless Applications
Introduction to AWS Lambda and Serverless ApplicationsIntroduction to AWS Lambda and Serverless Applications
Introduction to AWS Lambda and Serverless ApplicationsAmazon Web Services
 
Raleigh DevDay 2017: Building serverless web applications
Raleigh DevDay 2017: Building serverless web applicationsRaleigh DevDay 2017: Building serverless web applications
Raleigh DevDay 2017: Building serverless web applicationsAmazon Web Services
 

Mais procurados (20)

Serverless Applications with AWS SAM
Serverless Applications with AWS SAMServerless Applications with AWS SAM
Serverless Applications with AWS SAM
 
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
 
Building CICD Pipelines for Serverless Applications
Building CICD Pipelines for Serverless ApplicationsBuilding CICD Pipelines for Serverless Applications
Building CICD Pipelines for Serverless Applications
 
Building APIs with Amazon API Gateway: re:Invent 2018 Recap at the AWS Loft -...
Building APIs with Amazon API Gateway: re:Invent 2018 Recap at the AWS Loft -...Building APIs with Amazon API Gateway: re:Invent 2018 Recap at the AWS Loft -...
Building APIs with Amazon API Gateway: re:Invent 2018 Recap at the AWS Loft -...
 
Deep Dive on Serverless Application Development NY Loft
Deep Dive on Serverless Application Development NY LoftDeep Dive on Serverless Application Development NY Loft
Deep Dive on Serverless Application Development NY Loft
 
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
 
Unlocking Agility with the AWS Serverless Application Model (SAM)
Unlocking Agility with the AWS Serverless Application Model (SAM)Unlocking Agility with the AWS Serverless Application Model (SAM)
Unlocking Agility with the AWS Serverless Application Model (SAM)
 
AWS Serverless Development
AWS Serverless DevelopmentAWS Serverless Development
AWS Serverless Development
 
Getting Started with AWS Lambda Serverless Computing
Getting Started with AWS Lambda Serverless ComputingGetting Started with AWS Lambda Serverless Computing
Getting Started with AWS Lambda Serverless Computing
 
Introduction to Serverless computing and AWS Lambda - Floor28
Introduction to Serverless computing and AWS Lambda - Floor28Introduction to Serverless computing and AWS Lambda - Floor28
Introduction to Serverless computing and AWS Lambda - Floor28
 
Advanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step FunctionsAdvanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step Functions
 
Overview of Serverless Application Deployment Patterns - AWS Online Tech Talks
Overview of Serverless Application Deployment Patterns - AWS Online Tech TalksOverview of Serverless Application Deployment Patterns - AWS Online Tech Talks
Overview of Serverless Application Deployment Patterns - AWS Online Tech Talks
 
Getting Started with AWS Lambda & Serverless Computing
Getting Started with AWS Lambda & Serverless ComputingGetting Started with AWS Lambda & Serverless Computing
Getting Started with AWS Lambda & Serverless Computing
 
Local Testing and Deployment Best Practices for Serverless Applications - AWS...
Local Testing and Deployment Best Practices for Serverless Applications - AWS...Local Testing and Deployment Best Practices for Serverless Applications - AWS...
Local Testing and Deployment Best Practices for Serverless Applications - AWS...
 
AWS Lambda Layers, the Runtime API, & Nested Applications: re:Invent 2018 Rec...
AWS Lambda Layers, the Runtime API, & Nested Applications: re:Invent 2018 Rec...AWS Lambda Layers, the Runtime API, & Nested Applications: re:Invent 2018 Rec...
AWS Lambda Layers, the Runtime API, & Nested Applications: re:Invent 2018 Rec...
 
Advanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step FunctionsAdvanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step Functions
 
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...
 
Serverless Architecture Patterns
Serverless Architecture PatternsServerless Architecture Patterns
Serverless Architecture Patterns
 
Introduction to AWS Lambda and Serverless Applications
Introduction to AWS Lambda and Serverless ApplicationsIntroduction to AWS Lambda and Serverless Applications
Introduction to AWS Lambda and Serverless Applications
 
Raleigh DevDay 2017: Building serverless web applications
Raleigh DevDay 2017: Building serverless web applicationsRaleigh DevDay 2017: Building serverless web applications
Raleigh DevDay 2017: Building serverless web applications
 

Semelhante a Building Advanced Serverless Applications

Designing and Implementing a Serverless Media Processing Workflow Using AWS S...
Designing and Implementing a Serverless Media Processing Workflow Using AWS S...Designing and Implementing a Serverless Media Processing Workflow Using AWS S...
Designing and Implementing a Serverless Media Processing Workflow Using AWS S...Amazon Web Services
 
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 Amazon Web Services
 
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...Amazon Web Services
 
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 WorkflowAmazon Web Services
 
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 FunctionsAmazon Web Services
 
AWS Step Functions을 활용한 서버리스 앱 오케스트레이션
AWS Step Functions을 활용한 서버리스 앱 오케스트레이션AWS Step Functions을 활용한 서버리스 앱 오케스트레이션
AWS Step Functions을 활용한 서버리스 앱 오케스트레이션Amazon Web Services Korea
 
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 2018AWS Germany
 
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 FunctionsAmazon Web Services
 
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 2017Amazon Web Services
 
Serverless Development Deep Dive
Serverless Development Deep DiveServerless Development Deep Dive
Serverless Development Deep DiveAmazon Web Services
 
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)Julien SIMON
 
How LEGO.com Accelerates With Serverless
How LEGO.com Accelerates With ServerlessHow LEGO.com Accelerates With Serverless
How LEGO.com Accelerates With ServerlessSheenBrisals
 
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 SeriesAmazon Web Services
 
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 FunctionsAmazon Web Services
 
使用 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)Amazon Web Services
 
Introduction to AWS Step Functions:
Introduction to AWS Step Functions: Introduction to AWS Step Functions:
Introduction to AWS Step Functions: Amazon Web Services
 
AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)
AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)
AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)AWSKRUG - AWS한국사용자모임
 
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 SymphonyAmazon Web Services
 
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 FunctionsAmazon Web Services Japan
 

Semelhante a Building Advanced Serverless Applications (20)

Designing and Implementing a Serverless Media Processing Workflow Using AWS S...
Designing and Implementing a Serverless Media Processing Workflow Using AWS S...Designing and Implementing a Serverless Media Processing Workflow Using AWS S...
Designing and Implementing a Serverless Media Processing Workflow Using AWS S...
 
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
 
Serverless Apps with AWS Step Functions
Serverless Apps with AWS Step FunctionsServerless Apps with AWS Step Functions
Serverless Apps with AWS Step Functions
 
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...
 
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
 
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을 활용한 서버리스 앱 오케스트레이션
 
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
 
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
 
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
 
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)
 
How LEGO.com Accelerates With Serverless
How LEGO.com Accelerates With ServerlessHow LEGO.com Accelerates With Serverless
How LEGO.com Accelerates With Serverless
 
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
 
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
 
使用 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)
 
Introduction to AWS Step Functions:
Introduction to AWS Step Functions: Introduction to AWS Step Functions:
Introduction to AWS Step Functions:
 
AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)
AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)
AWS Step Functions를 이용한 마이크로서비스 개발하기 - 김현민 (4CSoft)
 
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
 
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
 

Mais de Amazon Web Services

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...Amazon Web Services
 
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...Amazon Web Services
 
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 FargateAmazon Web Services
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSAmazon Web Services
 
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 Amazon Web Services
 
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...Amazon Web Services
 
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...Amazon Web Services
 
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 WorkloadsAmazon Web Services
 
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 sfatareAmazon Web Services
 
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 NodeJSAmazon Web Services
 
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 webAmazon Web Services
 
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 sfatareAmazon 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 AWSAmazon 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 DeckAmazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without serversAmazon 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
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceAmazon 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
 

Building Advanced Serverless Applications

  • 1. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Paul Maddox Developer Technologies, AWS April 2018 Building Advanced Serverless Applications with AWS Step Functions (starting 15:45) Twitter: @paulmaddox Email: pmaddox@amazon.com
  • 2. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. About me Paul Maddox Developer Technologies Amazon Web Services • 16 years of dev, SRE, and systems architecture background • 7 of 7 AWS certifications • Developer: Go/Java/C/Node • Creator of AWS SAM Local Twitter: @paulmaddox Email: pmaddox@amazon.com @paulmaddox
  • 3. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. "Serverless requires me to develop in a completely different way" Myth Busting Time…
  • 4. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. "Serverless isn't for advanced applications" Myth Busting Time…
  • 7. "I want to sequence functions" "I want to select functions based on data" "I want to retry functions" "I want try/catch/finally" Functions into apps "I have code that runs for hours" "I want to run functions in parallel"
  • 8. Coordination must-haves • Scales out • Doesn’t lose state • Deals with errors/timeouts • Easy to build & operate • Auditable
  • 9. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. “Any sufficiently complicated model class contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of a state machine.” http://raganwald.com/2018/02/23/forde.html
  • 10. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. The problem is that you almost never create an object fully formed with all the behaviour it is ever going to need, rather you build it up over time. https://www.skorks.com/2011/09/why-developers-never-use-state-machines/
  • 11. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 12. Application Lifecycle in AWS Step Functions Visualize in the Console Define in JSON Monitor Executions
  • 13. Define in JSON and Then Visualize in the Console { "Comment": "Hello World Example", "StartAt" : "HelloWorld", "States" : { "HelloWorld" : { "Type" : "Task", "Resource" : "${lambdaArn}", "End" : true } } }
  • 14. Execute One or One Million Start End HelloWorld Start End HelloWorld Start End HelloWorld Start End HelloWorld Start End HelloWorld Start End HelloWorld Start End HelloWorld Start End HelloWorld
  • 15. Maximum Execution Time AWS Lambda Functions 5 minutes AWS Step Functions State Machines 1 year
  • 16. Monitor Executions from the Console
  • 17. 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
  • 18. © 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 …", … } }
  • 19. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. ExtractImageMetadata 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
  • 20. API actions on activity task Register Activity Task - Returns ARN Poll For task (by ARN) Report Success Report Failure Report Heartbeat
  • 21. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. O pen Source A pache License https://states-language.net/spec.html
  • 22. © 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
  • 23. Build Visual Workflows from State Types Task Choice Fail Parallel
  • 24. Serverless Human Approval Tasks https://aws.amazon.com/blogs/compute/ implementing-serverless-manual-approval-steps-in-aws-step-functions-and-amazon-api-gateway/
  • 25. Image Recognition and Processing Backend Task Choice Fail Parallel https://github.com/awslabs/lambda-refarch-imagerecognition
  • 26. Amazon EBS Snapshot Management State Machine State Machine create-snapshot complete event copy-snapshot complete event Primary Region DR Region Parallel State Choice Tag Snapshot Count Snapshots CopyToDRRegion Success State Delete Snapshots Choice Tag SnapshotCopy Count Snapshots Pass State Delete Snapshots Notification Topic Errors Sent to SNS Notification Topic Errors Sent to SNS https://github.com/awslabs/aws-step-functions-ebs-snapshot-mgmt 1. Tag 2. Count 3. Copy to DR region 4. Delete Expired Whenever a new EBS snapshot completes: State Machines invoked by Amazon CloudWatch Events
  • 27. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Who's using this in production?
  • 28. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Vending Pass problem 1. Thirsty consumer presents card, can buy a drink with Vending Pass or debit 2. But mobile wallet display can get out of sync under certain conditions 3.
  • 29. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Vending Pass problem • Use Step Functions to co- ordinate and verify state • Cheap and simple!
  • 30. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. • Transcode 350 clips/day into 14 formats, fast • It’s all done with FFmpeg. The processing time is just about 100% of the video length • Aargh! Video processing problem
  • 31. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. • Derive keyframe locations within the source • Split the source at the keyframes • Process segments (typically 0.5 sec per) in parallel • Concatenate segments • Elapsed time: ~20 min down to ~2 minutes Video processing solution
  • 32. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Details How to get from Lambda to Amazon S3: ffmpeg -f concat –safe 0 -I filelist.ffcat –c copy pipe:0 | aws s3 cp – s3://output-bucket/output-file.mp4
  • 33. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Details
  • 34. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Let’s peek at the code! "Init": { "Type": "Pass", "ResultPath": "$.operation", "Result": "prepare-split", "Next": "PrepareSplit" }, "PrepareSplit": { "Type": "Task", "Resource": "arn:…:ffmpeg-18HFP9FXFL6P", "Next": "SplitPrepared" }, "SplitPrepared": { "Type": "Pass", "ResultPath": "$.operation", "Result": "perform-split", "Next": "PerformSplit" }, "PerformSplit": { "Type": "Task", "Resource": "arn:…:ffmpeg-18HFP9FXFL6P", "Next": "SplitPerformed" }, "SplitPerformed": { "Type": "Pass", "ResultPath": "$.operation", "Result": "poll-results", "Next": "PreparePoll" }, "PreparePoll": { "Type": "Pass", "ResultPath": "$.pollstatus", "Result": "Submitted", "Next": "WaitForResults" } Hmm…the same function, throughout
  • 35. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Let’s peek at the code! "WaitForResults": { "Type": "Choice", "Choices": [ { "Variable": "$.pollstatus", "StringEquals": "Complete", "Next": "SegmentsCompleteState" }, { "Variable": "$.pollstatus", "StringEquals": "Progressing", "Next": "loop_wait_using_seconds" }, { "Variable": "$.pollstatus", "StringEquals": "Submitted", "Next": "loop_wait_using_seconds" } ] } "loop_wait_using_seconds": { "Type": "Wait", "Seconds": 3, "Next": "loop" }, "loop": { "Type": "Task", "Resource": "arn:…:ffmpeg-18HFP9FXFL6P", "Next": "WaitForResults" }, "SegmentsCompleteState": { "Type": "Pass", "ResultPath": "$.operation", "Result": "concat", "Next": "CompleteState" }, "CompleteState": { "Type": "Task", "Resource": " arn:…:ffmpeg-18HFP9FXFL6P", "End": true } Counts the segments, sets $.pollstatus Stitches segments together
  • 36. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Takeaways Use Amazon S3 data events to trigger parallel Lambda processing: win Use Amazon S3 URLs to stream video to Lambda: win Scaling to 1,000 Lambdas, rather than 1,000 EC2 instances: win Process video segments in parallel: win
  • 37. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 1. Sometimes Lambda is best, sometimes ECS 2. Previously, all tied together with pub/sub and procedural code 3. Aargh! Media transcoding problem
  • 38. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 1. Use state machines to pick execution engine 2. Use CloudWatch Events for messaging and triggering Step Functions Media transcoding solution
  • 39. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Let’s peek at the code! "Encoder Decider": { "Type": "Choice", "Default": "Run ECS Encoder", "Choices": [ { "Next": "Run Lambda Encoder", "And": [ { "Variable": "$.asset.size", "NumericLessThanEquals": 2000000000 }, { "Variable": "$.asset.duration_ms", "NumericLessThanEquals": 10000 } ] } ] } Hmm…maybe "Default" should have been called "Else"
  • 40. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Let’s peek at the code! "Run ECS Encoder": { "Type": "Task", "Resource": "arn:…SubmitECSTask", "Retry": [ { "ErrorEquals": [ "NoResourceInCluster" ], "IntervalSeconds": 5, "MaxAttempts": 720, "BackoffRate": 1.0 } ], "ResultPath": "$.task", "Next": "Wait X Seconds" } Hmm…every 5 seconds, for an hour?! "Wait X Seconds": { "Type": "Wait", "SecondsPath": "$.task.wait_time", "Next": "Get ECS Task Status" }, "Get ECS Task Status": { "Type": "Task", "Resource": "arn:…ECSTaskStatus", "Next": "ECS Task Complete?", "ResultPath": "$.task.status" }
  • 41. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Let’s peek at the code! "ECS Task Complete?": { "Type": "Choice", "Choices": [ { "And": [ { "Variable": "$.task.status", "StringEquals": "FAILED" }, { "Variable": "$.task.attempt", "NumericGreaterThanEquals": 3 } ], "Next": "Fire Failed Event" }, { "Variable": "$.task.status", "StringEquals": "FAILED", "Next": "Run ECS Encoder" }, { "Variable": "$.task.status", "StringEquals": "SUCCEEDED", "Next": "Fire Successful Event" } ], "Default": "Wait X Seconds" }, "Fire Successful Event": { "Type": "Task", "Resource": "aws:…SendSuccessfulEvent", "End": true }, "Fire Failed Event": { "Type": "Task", "Resource": "aws:…SendFailedEvent", "End": true } These fire CloudWatch Events
  • 42. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Takeaways Passing a correlation ID through a complex serverless app: win SAM to make code changes auditable: win Code Pipeline for CI/CD: winCloudWatch Events pattern matching: win
  • 43. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. More state machines Image Recognition and Processing BackendEBS Snapshot Management https://aws.amazon.com/step-functions/getting-started
  • 44. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. What are you building? #stepfunctions https://console.aws.amazon.com/states/
  • 45. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Thank you! Twitter: @paulmaddox Email: pmaddox@amazon.com@paulmaddox