Top Banner
Ganz ohne Server: Betreiben hockskalierbarer Microservices mit AWS Lambda Oliver Arafat, Enterprise Evangelist AWS [email protected] @OliverArafat Microservices Webday
31

AWS Lambda Live Demo - Microservices Web Day

Apr 15, 2017

Download

Technology

AWS Germany
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: AWS Lambda Live Demo - Microservices Web Day

Ganz ohne Server: Betreiben hockskalierbarer

Microservices mit AWS Lambda

Oliver Arafat, Enterprise Evangelist AWS

[email protected]

@OliverArafat

Microservices Webday

Page 2: AWS Lambda Live Demo - Microservices Web Day

Agenda

• A simple problem, a complicated solution

• What is AWS Lambda?

• Pricing

• Common Use-Cases

• Demo

Page 3: AWS Lambda Live Demo - Microservices Web Day

Simple Problem:

Let’s make a microservice to thumbnail an image as soon as it’s uploaded

into a repository.

Page 4: AWS Lambda Live Demo - Microservices Web Day

• Provision a fleet of proxy machines to capture

uploads.

• For each upload, enqueue a job to process it.

• Provision a second fleet of machines to read and

process jobs.

• Pick a deployment solution.

• Plan capacity, accounting for fault tolerance, good

long-term utilization, burst capability, etc.

• Monitor 24x7x365 for capacity, health, security, etc.

• Migrate to new instance types over time, keeping OS

and language runtimes patched and up to date.

Page 5: AWS Lambda Live Demo - Microservices Web Day

What if there was a better way?

Please meet AWS Lambda.

Page 6: AWS Lambda Live Demo - Microservices Web Day

What if every AWS service generated events…?

PUT

COPY

UPDATE

DELETE

RESTORE

Amazon

S3

… and you could respond to them easily?

Page 7: AWS Lambda Live Demo - Microservices Web Day

Event-Driven Compute

– Stateless, request-driven code called Lambda

functions

– Triggered by events in other services:

• S3

• DynamoDB Streams

• Amazon Kinesis Streams

• Amazon SNS

• Amazon Cognito

• CloudTrail Audit Logs

Page 8: AWS Lambda Live Demo - Microservices Web Day

AWS Lambda: Hello World!

// import any 3rd party library you want

exports.handler = function(event, context) {

context.succeed(‘Hello ’ + event.param);// context.fail('Something went wrong');

};

Page 9: AWS Lambda Live Demo - Microservices Web Day

Push Event Model

• Unordered model

• 3 retries

Page 10: AWS Lambda Live Demo - Microservices Web Day

Pull Event Model

• Ordered model with multiple records per event

• Unlimited retries (until data expires)

Page 11: AWS Lambda Live Demo - Microservices Web Day

No Infrastructure to Manage

Focus on business logic, not infrastructure.

Just upload your code; AWS Lambda handles:

Capacity

Scaling

Deployment

Fault tolerance

Monitoring

Logging

Web service front end

Security patching

Page 12: AWS Lambda Live Demo - Microservices Web Day

Automatic scaling

• Each event becomes a Lambda request

(hands free delivery)• For example, each object uploaded to Amazon S3

is an event

• Lambda scales to match the event rate

• You can’t over or under provision

• You pay only for what they use

Page 13: AWS Lambda Live Demo - Microservices Web Day

Bring your own code (BYOC)

• Create threads and processes

• Run batch scripts or other executables

• Read/write files in /tmp

• Include any library with a Lambda

function code, even native libraries

Page 14: AWS Lambda Live Demo - Microservices Web Day

Intelligent Infrastructure

• Turn storage services like Amazon S3 and

Amazon Dynamo into dynamic, reactive services.

• Attach code to a stream so that it can

automatically aggregate or transform data

flowing through.

• Cost effectively add even small amounts of code,

like audit checks, where you need them.

Page 15: AWS Lambda Live Demo - Microservices Web Day

Amazon EC2/ECS

• Hourly infrastructure rental

• Flexible – choose your OS

and instance type

• DIY fault tolerance

• Scale by provisioning

more instances

• Any code, any language

Comparing AWS Compute Offerings

AWS Lambda

• Request-driven

• Simple – shared OS,

AWS-owned infrastructure

• Built-in fault tolerance

• Scale by sending more requests

• Stateless Node.js and Java code

Page 16: AWS Lambda Live Demo - Microservices Web Day

Pricing

Page 17: AWS Lambda Live Demo - Microservices Web Day

Fine-grained pricing

• Compute time is charged by 100ms, so even short jobs make sense

• Low per request charge

• No hourly, daily, or monthly minimums

• Free tier

Page 18: AWS Lambda Live Demo - Microservices Web Day

Pricing Example (1)

Total Charges = Compute Charges + Request Charges

Compute Charges:

• First 1 million requests per month are free

• $0.20 per 1 million requests thereafter ($0.0000002 per request)

Request Charges:

• $0.00001667 for every GB-second

Page 19: AWS Lambda Live Demo - Microservices Web Day

Pricing Example (2)

If you allocated 128MB of memory to your function,

executed it 30 million times in one month, and it ran for 200ms each time,

your charges would be calculated as follows:

Total compute (seconds) = 30M * (0.2sec) = 6,000,000 seconds

Total compute (GB-s) = 6,000,000 * 128MB/1024 = 750,000 GB-s

Total Compute – Free tier compute = Monthly billable compute seconds

750,000 GB-s – 400,000 free tier GB-s = 350,000 GB-s

Monthly compute charges = 350,000 * $0.00001667 = $5.83

30M requests – 1M free tier requests = 29M Monthly billable requests

Monthly request charges = 29M * $0.2/M = $5.80

Total charges = Compute charges + Request charges = $5.83 + $5.80 = $11.63 per month

Page 20: AWS Lambda Live Demo - Microservices Web Day

Common Use Cases

Page 21: AWS Lambda Live Demo - Microservices Web Day

Data Triggers: Amazon S3

Amazon S3 Bucket Events AWS Lambda

Original image Thumbnailed image

1

2

3

Page 22: AWS Lambda Live Demo - Microservices Web Day

Data Triggers: DynamoDB

AWS Lambda

DynamoDB

Table and Stream

Send Amazon SNS

notifications

Update another table

Page 23: AWS Lambda Live Demo - Microservices Web Day

Audit and Notify

AWS API calls

AWS CloudTrail Logs

AWS Lambda

Bucket events Amazon SNS

notifications

Page 24: AWS Lambda Live Demo - Microservices Web Day

Custom Events

AWS Lambda

Page 25: AWS Lambda Live Demo - Microservices Web Day

Serverless Microservices

AWS Lambda

API Gateway

Page 26: AWS Lambda Live Demo - Microservices Web Day

Demo

Page 27: AWS Lambda Live Demo - Microservices Web Day

Migrating a NODE.JS Service to AWS Lambda

Page 28: AWS Lambda Live Demo - Microservices Web Day

Migrating a NODE.JS Service to AWS Lambda

Page 29: AWS Lambda Live Demo - Microservices Web Day

Migrating a NODE.JS Service to AWS Lambda

Page 30: AWS Lambda Live Demo - Microservices Web Day

AWS Free Tier

aws.amazon.com/free

Page 31: AWS Lambda Live Demo - Microservices Web Day

Thank you!

Questions?

Oliver Arafat, Enterprise Evangelist AWS

[email protected]

@OliverArafat

Microservices Webday