100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating...

Post on 26-Jun-2018

224 views 0 download

Transcript of 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating...

100% serverless: Operating highly-scalable microservices with AWS Lambda

Oliver Arafat, Enterprise Evangelist AWS

arafato@amazon.de @OliverArafat

Agenda

•  A simple problem, a complicated solution •  What is AWS Lambda? •  Pricing •  Common Use-Cases •  Demo

Simple Problem:

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

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

What if there was a better way? Please meet AWS Lambda.

What if every AWS service generated events…?

PUT

COPY

UPDATE

DELETE

RESTORE

Amazon S3

… and you could respond to them easily?

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

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'); };

Virtual Machines Containers Functions

Different levels of granularity on AWS

Python support

Scheduled Events

New features in AWS Lambda

Long-running functions (max 5 minutes)

VPC Integration

Versioning and aliasing

Push Event Model

•  Unordered model •  3 retries

Pull Event Model •  Ordered model with multiple records per event •  Unlimited retries (until data expires)

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

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

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

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.

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, Java and Python code

Pricing

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

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

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

Cron Job executed once a day running for a couple of seconds

The other 99.999% of the day your server sits idle – and yet you’re paying for it

30 * 5sec = 150 secs * 128MB/1024 = 18.75 GB-s * $0.00001667 = $0,00031

400,000 GB-s ($6.66) for free every month

Total charges = Compute charges + Request charges

We charge you $0.20 per 1 Mio requests… and the first million is on us, every month.

Total charges = $0.00

Lambda lets you write very cost-efficient Cron Jobs

Common Use Cases

Data Triggers: Amazon S3

Amazon S3 Bucket Events AWS Lambda λ

Original image Thumbnailed image

1

2

3

Data Triggers: DynamoDB

AWS Lambda λ

DynamoDB Table and Stream

Send Amazon SNS notifications

Update another table

Audit and Notify

AWS API calls

AWS CloudTrail Logs

AWS Lambda λBucket events Amazon SNS

notifications

Custom Events

AWS Lambda λ

Serverless Microservices

AWS Lambda λ

API Gateway

Demo

Migrating a NODE.JS Service to AWS Lambda

Migrating a NODE.JS Service to AWS Lambda

Migrating a NODE.JS Service to AWS Lambda

Thank you!

Questions?

Oliver Arafat, Enterprise Evangelist AWS

arafato@amazon.de @OliverArafat

Microservices Webday