Microservices without the Servers: AWS Lambda in Action Dr. Tim Wagner, General Manager AWS Lambda August 19, 2015 Seattle, WA 2015, Amazon Web Services, Inc. or its affiliates. All rights reserved
Two Minute AWS Lambda Origin Story
Evolution of Storage Objects (files) Disks Data Center
Evolution of Storage: Cloud Store Amazon S3
Sharing = Lower Costs Amazon S3
Evolution of Storage Compute Functions Server Racks / VMs Data Center
Evolution of Compute Containers Amazon EC2 Container Service (ECS)
Evolution of Compute Amazon EC2 Container Service (ECS)
Evolution of Compute Amazon EC2 Container Service (ECS)
Evolution of Compute Containers Amazon EC2 Container Service (ECS)
Evolution of Compute Containers Amazon EC2 Container Service (ECS)
Evolution of Compute Containers Amazon EC2 Container Service (ECS)
Evolution of Compute: Lambda AWS Lambda
Sharing = Lower Costs AWS Lambda
The 2015 LinuxCon Challenge Build an image-processing microservice that Scales per request Can run native binaries and executables/processes Requires no deployment effort Fault tolerant and multi-region Includes both web and mobile clients
The Catch Do it without: Servers Monolithic app or explicit web service Explicit code for scaling or fault tolerance Paying for idle time and get it done in 45 minutes!
Serverless Microservice Architecture Static web content served from Amazon S3 Web Client Mobile Client Amazon API Gateway AWS Lambda + ImageMagick
Step 1 An ImageMagick Server in AWS Lambda
What we re going to do 1. Create an AWS Lambda function 1. Choice of languages (Java, nodejs, Scala, Clojure, ). We ll use nodejs to make it easy to edit in the console. 2. With nodejs on Lambda, ImageMagick is built in but you could also use PIL or 3 rd party libraries (even native ones). 2. Add a little code to indicate which command to run (convert, thumbnail, get metadata, etc.)
Diving Deeper: Resource Sizing AWS Lambda offers 23 power levels Higher levels offer more memory and more CPU power 128 MB, lowest CPU power 1.5 GB, highest CPU power Higher power levels == lower latency for CPUbound and bursty tasks Compute price scales with the power level
Step 2 Mobile App
Lambda Function == Mobile Backend AWS Lambda hosts and scales the code AWS Mobile SDK on the device ios, Android/Fire, Xamarin, Unity Device and user context sent automatically Mobile App AWS Lambda
What we re going to do 1. Create an app in Android studio, 2. Using Amazon Cognito to authenticate, 3. And a simple POJO to send images and commands to our AWS Lambda function
Step 3 Build a (serverless) multi-region deployment system
AWS Lambda Regions NEW Tokyo launched 6/29 AWS Lambda Region
Building a single-region Auto-Deployer Lambda ZIP Deployment Function Amazon S3 Bucket AWS Lambda
Building a multi-region Auto-Deployer Lambda ZIP Ireland Deployment Function Cross- Region Replication Amazon S3 Bucket Deployment Function AWS Lambda Tokyo Amazon S3 Bucket AWS Lambda
What we re going to do 1. Take a few lines of code that deploy an AWS Lambda function from Amazon S3 to a single region. 2. Turn it into an Amazon S3 event handler. 3. Upload our image processing microservice. 4. Turn on S3 cross-region replication. 5. Watch our function deploy automagically!
Step 4 Enable Web Clients using Amazon API Gateway
Serverless Microservice Architecture Static web content served from Amazon S3 Web Client Mobile Client Amazon API Gateway AWS Lambda + ImageMagick
Amazon API Gateway Host multiple versions and stages of your API Create and distribute API keys to developers Throttle and monitor calls Cache responses Transform data Generate SDKs (including Swagger support)
What we re going to do 1. Create and populate an image processing API 2. Test it from within Amazon API Gateway 3. Deploy it Not shown and needed for demo: CORS (see docs) Not shown, but supported: Vanity URL
Step 5 Testing
AWS Lambda as a Scalable Testing Platform Unit Testing Function HTTPS Invoke Function Image Processing Microservice Outcome stored in Amazon DynamoDB
AWS Lambda as a Scalable Testing Platform Unit Testing Function HTTPS Invoke Function Image Processing Microservice Unit Testing Function HTTPS Invoke Function Image Processing Microservice Load Testing Function Unit Testing Function Unit Testing Function HTTPS Invoke Function HTTPS Invoke Function Image Processing Microservice Image Processing Microservice
What we re going to do 1. Call our URL endpoint from within Lambda. 2. Turn this into a unit test by storing the outcome in Amazon DynamoDB. 3. Turn this into a load test by doing it N times.
Step 6 A Serverless Website using Amazon S3
What we re going to do 1. Create a single page webapp 2. Configure S3 bucket for static website content 3. Test in a browser
More Bells and Whistles
Features you can add 1. Make a photo-sharing site: Add OAuth to the mobile app with Amazon Cognito user identity. 2. Add client-side analytics with Amazon Mobile Analytics. 3. Add server-side telemetry using Amazon Kinesis + Lambda. 4. Bring your own image processing libraries (native code is supported).
What else can you do with AWS Lambda? Scalable IoT Backends NoSQL DB Triggers Extending Platforms Adding a Feature to Amazon S3 Real-Time Streaming Analysis
Join the serverless revolution!
Go to the AWS Lambda console, create a function, and run it. (The first million invokes are on us!)
Congrats, you re a Lambda function expert! Add an event source or an HTTP endpoint.
Build the world s easiest mobile backend. (Hint: Start with the built-in CRUD sample!)
Follow AWS Lambda aws.amazon.com/blogs/compute aws.amazon.com/lambda AWS Lambda Forum
Come Meet the Team! WHERE Mayflower Park Hotel 405 Olive Way WHEN Wednesday, August 19, 2015 5:00-7:00pm