microservices without the servers: aws lambda in action · microservices without the servers: aws...

48
©2015, Amazon Web Services, Inc. or its affiliates. All rights reserved Microservices without the Servers: AWS Lambda in Action Dr. Tim Wagner, General Manager AWS Lambda August 19, 2015 | Seattle, WA

Upload: buikiet

Post on 28-Apr-2018

249 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

©2015, Amazon Web Services, Inc. or its affiliates. All rights reserved

Microservices without the Servers:

AWS Lambda in Action

Dr. Tim Wagner, General Manager AWS Lambda

August 19, 2015 | Seattle, WA

Page 2: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Two Minute AWS Lambda

Origin Story

Page 3: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Evolution of Storage

Data Center

Disks

Objects (files)

Page 4: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Evolution of Storage: Cloud Store

Amazon S3

Page 5: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Sharing = Lower Costs

Amazon S3

Page 6: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Evolution of Storage Compute

Data Center

Server Racks / VMs

Functions

Page 7: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Evolution of Compute

Amazon EC2 Container Service (ECS)

Containers

Page 8: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Evolution of Compute

Amazon EC2 Container Service (ECS)

Page 9: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Evolution of Compute

Amazon EC2 Container Service (ECS)

Page 10: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Evolution of Compute

Amazon EC2 Container Service (ECS)

Containers

Page 11: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Evolution of Compute

Amazon EC2 Container Service (ECS)

Containers

Page 12: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Evolution of Compute

Amazon EC2 Container Service (ECS)

Containers

Page 13: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Evolution of Compute: Lambda

AWS Lambda

Page 14: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Sharing = Lower Costs

AWS Lambda

Page 15: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

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 2015 LinuxCon Challenge

Page 16: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

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!

The Catch

Page 17: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Serverless Microservice Architecture

Static web content

served from

Amazon S3

AWS Lambda

+ ImageMagick

Web Client

Amazon API

Gateway

Mobile Client

Page 18: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Step 1

An ImageMagick Server

in AWS Lambda

Page 19: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

What we’re going to do

1. Create an AWS Lambda function1. 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 3rd party libraries (even native ones).

2. Add a little code to indicate which command to

run (convert, thumbnail, get metadata, etc.)

Page 20: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

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

Page 21: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Step 2

Mobile App

Page 22: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

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

AWS LambdaMobile App

Page 23: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

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

Page 24: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Step 3

Build a (serverless) multi-region

deployment system

Page 25: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

AWS Lambda Regions

NEW Tokyo

launched 6/29

AWS Lambda

Region

Page 26: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Building a single-region Auto-Deployer

Amazon S3 Bucket AWS Lambda

Lambda ZIP

Deployment

Function

Page 27: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Building a multi-region Auto-Deployer

Amazon S3 Bucket AWS Lambda

Lambda ZIP

Deployment

Function

Amazon S3 Bucket AWS Lambda

Deployment

Function

Ireland

Tokyo

Cross-

Region

Replication

Page 28: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

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!

Page 29: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Step 4

Enable Web Clients using

Amazon API Gateway

Page 30: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Serverless Microservice Architecture

Static web content

served from

Amazon S3

AWS Lambda

+ ImageMagick

Web Client

Amazon API

Gateway

Mobile Client

Page 31: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

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)

Page 32: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

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

Page 33: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Step 5

Testing

Page 34: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

AWS Lambda as a Scalable Testing Platform

HTTPS

Invoke

Function

Image

Processing

Microservice

Unit

Testing

Function

Outcome stored in

Amazon DynamoDB

Page 35: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

AWS Lambda as a Scalable Testing Platform

Load

Testing

Function

HTTPS

Invoke

Function

Image

Processing

Microservice

Unit

Testing

Function

HTTPS

Invoke

Function

Image

Processing

Microservice

Unit

Testing

Function

HTTPS

Invoke

Function

Image

Processing

Microservice

Unit

Testing

Function

HTTPS

Invoke

Function

Image

Processing

Microservice

Unit

Testing

Function

Page 36: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

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.

Page 37: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Step 6

A Serverless Website

using Amazon S3

Page 38: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

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

Page 39: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

More Bells and Whistles

Page 40: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

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).

Page 41: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

What else can you do with AWS Lambda?

NoSQL DB

Triggers

Adding a Feature

to Amazon S3

Extending

Platforms

Scalable IoT

Backends

Real-Time

Streaming

Analysis

Page 42: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Join the serverless revolution!

Page 43: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Go to the AWS Lambda

console, create a function,

and run it.(The first million invokes are on us!)

Page 44: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Congrats, you’re a

Lambda function expert!

Add an event source or

an HTTP endpoint.

Page 45: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Build the world’s easiest

mobile backend.(Hint: Start with the built-in CRUD sample!)

Page 46: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Follow AWS Lambda

aws.amazon.com/blogs/compute

aws.amazon.com/lambda

AWS Lambda Forum

Page 47: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable

Come Meet the Team!

Mayflower

Park Hotel

405 Olive Way

WHERE

Wednesday,

August 19, 2015

5:00 - 7:00pm

WHEN

Page 48: Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS Lambda in Action ... mobile app with Amazon Cognito user identity. 2. ... Scalable