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"
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
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 …", … } }
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
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
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
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.
rights reserved. Vending Pass problem • Just wait for backend to catch up • Create a two-step state machine: • Wait (90 seconds) • Update mobile wallet • Cheap and simple!
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
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
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
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
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
rights reserved. 1. Use state machines to pick execution engine 2. Use CloudWatch Events for messaging and triggering Step Functions Media transcoding solution
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: win CloudWatch Events pattern matching: win
rights reserved. More state machines Image Recognition and Processing Backend EBS Snapshot Management https://aws.amazon.com/step-functions/getting-started