Anda di halaman 1dari 48

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

Mobile Client
Web Client

Amazon API AWS Lambda


Gateway + ImageMagick
Step 1

An ImageMagick Server
in AWS Lambda
What were going to do

1. Create an AWS Lambda function


1. Choice of languages (Java, nodejs, Scala, Clojure, ). Well
use nodejs to make it easy to edit in the console.
2. With nodejs on Lambda, ImageMagick is built inbut you
could also use PIL or 3rd 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 CPU-
bound 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 Mobile App AWS Lambda
iOS, Android/Fire, Xamarin,
Unity
Device and user context
sent automatically
What were 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

Deployment
Function

Ireland

Cross-
Amazon S3 Bucket AWS Lambda
Region
Replication Deployment
Function

Tokyo

Amazon S3 Bucket AWS Lambda


What were 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

Mobile Client
Web Client

Amazon API AWS Lambda


Gateway + 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 were 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 HTTPS Image


Testing Invoke Processing
Function Function Microservice

Outcome stored in
Amazon DynamoDB
AWS Lambda as a Scalable Testing Platform

Unit HTTPS Image


Testing Invoke Processing
Function Function Microservice

Unit HTTPS Image


Testing Invoke Processing
Function Function Microservice

Load Unit HTTPS Image


Testing Invoke Processing
Testing Function Function Microservice
Function
Unit HTTPS Image
Testing Invoke Processing
Function Function Microservice
What were 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 were 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 NoSQL DB Extending Adding a Feature Real-Time


Backends Triggers Platforms to Amazon S3 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, youre a
Lambda function expert!
Add an event source or
an HTTP endpoint.
Build the worlds 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 WHEN

Mayflower Wednesday,
Park Hotel August 19, 2015
405 Olive Way 5:00 - 7:00pm

Anda mungkin juga menyukai