Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS...

Post on 28-Apr-2018

238 views 0 download

Transcript of Microservices without the Servers: AWS Lambda in Action · Microservices without the Servers: AWS...

©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

Two Minute AWS Lambda

Origin Story

Evolution of Storage

Data Center

Disks

Objects (files)

Evolution of Storage: Cloud Store

Amazon S3

Sharing = Lower Costs

Amazon S3

Evolution of Storage Compute

Data Center

Server Racks / VMs

Functions

Evolution of Compute

Amazon EC2 Container Service (ECS)

Containers

Evolution of Compute

Amazon EC2 Container Service (ECS)

Evolution of Compute

Amazon EC2 Container Service (ECS)

Evolution of Compute

Amazon EC2 Container Service (ECS)

Containers

Evolution of Compute

Amazon EC2 Container Service (ECS)

Containers

Evolution of Compute

Amazon EC2 Container Service (ECS)

Containers

Evolution of Compute: Lambda

AWS Lambda

Sharing = Lower Costs

AWS Lambda

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

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

Serverless Microservice Architecture

Static web content

served from

Amazon S3

AWS Lambda

+ ImageMagick

Web Client

Amazon API

Gateway

Mobile Client

Step 1

An ImageMagick Server

in AWS Lambda

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

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

– iOS, Android/Fire, Xamarin,

Unity

• Device and user context

sent automatically

AWS LambdaMobile App

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

Amazon S3 Bucket AWS Lambda

Lambda ZIP

Deployment

Function

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

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

AWS Lambda

+ ImageMagick

Web Client

Amazon API

Gateway

Mobile Client

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

HTTPS

Invoke

Function

Image

Processing

Microservice

Unit

Testing

Function

Outcome stored in

Amazon DynamoDB

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

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?

NoSQL DB

Triggers

Adding a Feature

to Amazon S3

Extending

Platforms

Scalable IoT

Backends

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!

Mayflower

Park Hotel

405 Olive Way

WHERE

Wednesday,

August 19, 2015

5:00 - 7:00pm

WHEN