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

34
100% serverless: Operating highly-scalable microservices with AWS Lambda Oliver Arafat, Enterprise Evangelist AWS [email protected] @OliverArafat

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

Page 1: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

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

Oliver Arafat, Enterprise Evangelist AWS

[email protected] @OliverArafat

Page 2: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Agenda

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

Page 3: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Simple Problem:

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

Page 4: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

•  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: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

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

Page 6: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

What if every AWS service generated events…?

PUT

COPY

UPDATE

DELETE

RESTORE

Amazon S3

… and you could respond to them easily?

Page 7: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

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: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

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: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Virtual Machines Containers Functions

Different levels of granularity on AWS

Page 10: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Python support

Scheduled Events

New features in AWS Lambda

Long-running functions (max 5 minutes)

VPC Integration

Versioning and aliasing

Page 11: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Push Event Model

•  Unordered model •  3 retries

Page 12: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

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

Page 13: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

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 14: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

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 15: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

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 16: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

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 17: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

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

Page 18: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Pricing

Page 19: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

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 20: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

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 21: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

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 22: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

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

Page 23: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

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

Page 24: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Common Use Cases

Page 25: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Data Triggers: Amazon S3

Amazon S3 Bucket Events AWS Lambda λ

Original image Thumbnailed image

1

2

3

Page 26: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Data Triggers: DynamoDB

AWS Lambda λ

DynamoDB Table and Stream

Send Amazon SNS notifications

Update another table

Page 27: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Audit and Notify

AWS API calls

AWS CloudTrail Logs

AWS Lambda λBucket events Amazon SNS

notifications

Page 28: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Custom Events

AWS Lambda λ

Page 29: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Serverless Microservices

AWS Lambda λ

API Gateway

Page 30: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Demo

Page 31: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Migrating a NODE.JS Service to AWS Lambda

Page 32: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Migrating a NODE.JS Service to AWS Lambda

Page 33: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Migrating a NODE.JS Service to AWS Lambda

Page 34: 100% serverless: Operating highly-scalable microservices ... · 100% serverless: Operating highly-scalable microservices with AWS Lambda ... • Amazon SNS • Amazon Cognito ...

Thank you!

Questions?

Oliver Arafat, Enterprise Evangelist AWS

[email protected] @OliverArafat

Microservices Webday