In today's competitive environment, startups are increasingly focused on eliminating any undifferentiated heavy lifting. Come learn about various architectural patterns for building a scalable, function-rich data processing systems, using AWS Lambda and other AWS managed services. Come see how PlayOn! Sports went from a multi-layered architecture for video streaming to a streamlined and serverless system using Lambda and Amazon S3.
2. What to Expect from the Session
• Evolution of Cloud Compute toward Serverless
• What is AWS Lambda?
• Building a serverless data processing architecture
• Example of a live video processing architecture
• Real-time data processing architecture patterns
• Tips and tricks for using AWS Lambda
14. SOURCE of
data
Fleet of servers poll for
changes
Listening to source Pushes to queue Pull off queue
Fleet of servers act as
workers to process the data
Auto-scale
worker nodes
to adjust with
load
S3 objects
Amazon Kinesis records
DynamoDB tables
SNS messages
IoT devices
…
Cross-AZ
replication for
high
availability
Load
balancer to
distribute
traffic
Data Processing Architecture with Servers
Application code
15. SOURCE of
data
Attach a Lambda function
And that’s it!
Lambda does
Listening/polling
Queuing
Auto scaling
Redundancy
Load balancing
Data Processing Architecture Without Servers
Application code
17. Company Overview & Background
PlayOn! Sports streams live high school sports
Tools to produce & stream a professional broadcast
Inverse use case from typical media company
Many simultaneous events
Smaller audience for each (long tail)
Challenge: transcode many live video streams at once
Peak hour @ 300 live inbound streams and 20k viewers
21. What We Learned
So far, Lambda works as expected
Functions can be built and deployed with minimal effort
Successfully able to focus on the domain-specific part of
our problem (video) with minimal ops work
Need to ensure we handle Lambda jobs not completing
Use SNS to work around S3 event notification method
Cost savings appear to be one order of magnitude
24. Demo – Video Clip Transcode
// Transcode video files uploaded to an S3 bucket
var async = require('async');
var fs = require('fs');
var exec = require('child_process').exec;
var aws = require('aws-sdk');
var s3 = new aws.S3();
// Lambda entry point
exports.handler = function(event, context) {
var inputVideo = '/tmp/myVideo.avi';
var outputVideo = '/tmp/myVideo.mp4';
var inputBucket = event.Records[0].s3.bucket.name;
var inputKey = event.Records[0].s3.object.key;
var outputBucket = inputBucket + '-out';
var outputKey = inputKey.substr(0,inputKey.length-4) + '.mp4';
// Runs the array of functions in series, each passing their results to the next
async.waterfall([
Set up variables
Serialize steps
25. Demo – Video Clip Transcode
// Download the object from S3 into a buffer
function download(next) {
s3.getObject({Bucket: inputBucket, Key: inputKey}, next); },
// Write the buffer to a file
function write(response, next) {
fs.writeFile(inputVideo, response.Body, next); },
// Spawn a process to transcode
function transcode(next) {
exec("./ffmpeg -i " + inputVideo + " -vcodec mpeg4 -b:v 1200k “
+ outputVideo, next); },
// Read the file to a buffer
function read(next) {
fs.readFile(outputVideo, next); },
// Upload the buffer to an object in S3
function upload(objectBuffer, next) {
s3.putObject({Bucket: outputBucket, Key: outputKey, Body: objectBuffer},
context.done); },
], context.fail);
};
Get file from S3
Write to disk
ffmpeg transcode
Read from disk
Upload to S3
26. Sample Real-Time Stream Processing Workflow
Using Amazon Kinesis & AWS Lambda
Amazon Kinesis AWS Lambda
Amazon Redshift
Amazon SNS
New records
available
27. Sample Real-Time DB Triggers Workflow Using
Amazon DynamoDB & AWS Lambda
New data
available
Amazon DynamoDB AWS Lambda
Amazon
DynamoDB
Amazon
Redshift
28. Sample Real-Time Message Handling Workflow
Using Amazon SNS & AWS Lambda
New message
published
Amazon SNS AWS Lambda
Amazon SNS
Amazon Kinesis
29. Sample CRUD Backend Workflow Using
Amazon API Gateway & AWS Lambda
New API
called
Amazon API Gateway AWS Lambda
Amazon S3
Amazon
DynamoDB
30. More Triggers for AWS Lambda
AWS
CloudFormation
Custom Resources
Amazon SES
Actions
Amazon Cognito
Sync Triggers
… and the list will
continue to grow!
AWS IoT ActionsAWS Lambda
Scheduled Events
Amazon Echo
Skills
Amazon SWF
Tasks
32. Using Lambda to Audit CloudTrail Activity
AWS
Lambda
Amazon S3Amazon CloudTrail
Amazon SNS
AWS IAM
33. Using Lambda for Automated Infrastructure
Management
AWS
Lambda
Amazon
SNS
Amazon
CloudWatch Alarm
ec2
runInstance
ecs
startTask
beanstalk
updateApp
kinesis
splitShard
Any API call
https://aws.amazon.com/blogs/compute/scaling-amazon-ecs-services-automatically-using-amazon-cloudwatch-and-aws-lambda/
34. Using Lambda to Forward AWS Events to
External Endpoints
http://danilop.net/aws/2015/07/26/sns2ifttt/ | https://github.com/danilop/SNS2IFTTT
AWS
Lambda
Amazon
SNS
IFTTT via
the Maker
channel
Amazon
CloudWatch Events
Auto Scaling
35. Using Lambda to Deploy Lambda Functions
https://aws.amazon.com/blogs/compute/dynamic-github-actions-with-aws-lambda/
AWS
Lambda
Amazon
SNS
GitHub Repo
lambda
createFn ()
36. A Few Other Tips and Tricks for Extending
AWS Lambda Functionality
Use /tmp space as cache
Run arbitrary binaries
Use Grunt and Jenkins plugins for deploying
Hook up to Slack
Build event-driven Amazon ECS
Try out JAWS: The Server-less Application Framework