serverless design patterns with aws lambda (philly ese)
TRANSCRIPT
![Page 1: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/1.jpg)
©2015, Amazon Web Services, Inc. or its affiliates. All rights reserved
Serverless Design Patterns with AWS Lambda
Dr. Tim Wagner General Manager, AWS Lambda and Amazon API Gateway
April 11, 2016
![Page 2: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/2.jpg)
![Page 3: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/3.jpg)
DevOps are 2016’s punch cards
![Page 4: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/4.jpg)
DevOps are 2016’s punch cards
Which operating system patch level?How many servers?What kind of
servers?
Which deployment
tool?
Are we running the right version?
Do we have the security
patch?
![Page 5: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/5.jpg)
Scalability, reliability, and fault tolerance are hard.
What if you could achieve them without working for it?
![Page 6: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/6.jpg)
A: ServerlessQ: What is the right
abstraction level for the cloud?
![Page 7: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/7.jpg)
PaaS
![Page 8: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/8.jpg)
PaaSToo curated Fat clients
Wrong unit: Deployed (monolithic) applications
![Page 9: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/9.jpg)
[Micro] Application Design for the Cloud
API
Function
API
Function
API
Function
API
Function
API
Function
![Page 10: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/10.jpg)
The Serverless Compute Manifesto
• Functions are the unit of deployment and scaling. • No machines, VMs, or containers visible in the programming model. • Permanent storage lives elsewhere. • Scales per request. Users cannot over- or under-provision capacity. • Never pay for idle (no cold servers/containers or their costs). • Implicitly fault tolerant because functions can run anywhere. • BYOC – Bring your own code. • Metrics and logging are a universal right.
![Page 11: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/11.jpg)
AWS Lambda and Amazon API Gateway
Microservices where you don’t have to think about:
• Servers • Being over/under capacity • Deployments • Scaling and fault tolerance • OS or language updates • Metrics and logging • Paying for idle time
…but where you can:
• Quickly code in the cloud • Bring your own code… even
native libraries • Create backends, event
handlers, and data processing systems
• Easily call enterprise APIs • Run code in parallel
Democratized scale!
![Page 12: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/12.jpg)
So… how do you build apps?
![Page 13: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/13.jpg)
What They Don’t Look Like
• Not monolithic – Expressed as a collection of independent functions – …with APIs where you need abstraction boundaries
• Skip the boring parts – AWS provides the webserver and API hosting
(plus, we need to see the requests) – AWS provides basic metrics and logging
(plus, it’s harder than it sounds)
• Skip the hard parts (distributed algorithms) – Fault-tolerance and scaling don’t show up in the app code
![Page 14: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/14.jpg)
What They *Do* Look Like
• Individual functions – Often with HTTP endpoints – Sometimes hooked up to events or other services
• Often asynchronous – That can also run on a schedule – Not necessarily simple
• Application scaling / parallelism should always be simple • Algorithms should be as complicated as they need to be
– Serverless scales down to a single line of Python…. – …and scales up to a 50+ MB C++ algorithm
![Page 15: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/15.jpg)
But… how do I scale, really?
![Page 16: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/16.jpg)
How to Run a 1 Hour Task
• Old school: Nice big server running for an hour • What happens if the machine dies or there’s an intermittent error? • Takes an hour. (Unless the machine dies, then it could take 2.) • What if it really only took 15 minutes? 75% waste…ugh. • Popular metaphor: Pets versus cattle
• New school: 60, 1-minute jobs • Who cares if a machine dies? That job just restarts. • Who cares what they run on? Perf comes from parallelism, not hw. • Done in a minute (worst case, 2). • No wasted time or money. Guaranteed. • Metaphor: Drive-through window
![Page 17: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/17.jpg)
What Programming Model???
• Choice of language – Java method – Python function – Node.js function – Bring your own (yep, we support that)
• Choice of library (anything you want) • JSON as schema / inter-service format • HTTPS on the wire
![Page 18: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/18.jpg)
Let’s see it…
![Page 19: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/19.jpg)
Events: JSON + Functions
Amazon S3 Amazon DynamoDB
Amazon Kinesis
AWS CloudFormatio
n
AWS CloudTrail
Amazon CloudWatch Logs / Events
Amazon SNSAmazonSWF
AmazonSES
AmazonAPI Gateway
Amazon Cognito
AWSIoT
![Page 20: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/20.jpg)
Example: Build an audit system in 5 minutes
1. Turn on AWS CloudTrails (AWS API logging). 2. Hook up Amazon CloudWatch events to
your AWS Lambda audit function. 3. Send yourself a text message if your filter
detects something suspicious.
Amazon CloudWatch Logs / Events
![Page 21: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/21.jpg)
Frameworks Bad; Services Good
• Amazon S3: object storage • Amazon DynamoDB: NoSQL database • Amazon SNS: messaging and notifications • Amazon Kinesis: real-time streaming • Amazon SES: email sending and receiving • Amazon CloudWatch Events: event hub • …and the rest of AWS • …and anything else on public Internet (aka “no lockin”) • …plus your own private APIs (aka “VPC” / enterprise)
![Page 22: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/22.jpg)
Drill-down: Resource Sizing in AWS Lambda
• 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 for CPU-bound and bursty tasks • Compute price scales with the power level • Billed duration ranges from 100ms to 5 minutes
![Page 23: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/23.jpg)
Drill-down: Versioning
• Immutable versions of your functions • One mutable working arena per function • Aliases: server-side updates • Blue/green deployments? Not needed, but… • Traffic shaping? Sure! (and easy) • API Gateway
– Immutable deployments – API stages – Swagger import (“API as code”)
• Goal: Open source microservice representation for both APIs and code
![Page 24: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/24.jpg)
But what *is* it?
• Linux containers as an implementation, not a programming or deployment abstraction – Process and network isolation, cgroups, seccomp, … – Off-the-shelf language runtimes – We minimize innovation here
• The world’s biggest bin-packing algorithm – High speed, highly distributed work routing and placement – We maximize innovation here
• Predictive capacity management – Purpose-built, massively scaled Language-Runtime-aaS
• API Gateway: Swagger interpreter as reverse proxy
![Page 25: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/25.jpg)
Serverless Design Patterns(or, What can you do with it?)
![Page 26: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/26.jpg)
Serverless Web Apps
1. Amazon S3 for serving static content 2. AWS Lambda for dynamic content 3. Amazon API Gateway for https access 4. Amazon DynamoDB for NoSQL data storage
Dynamic content in AWS Lambda
Data stored in Amazon
DynamoDB
API GatewayStatic content in Amazon S3
![Page 27: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/27.jpg)
A Scalable Backend for Mobile Apps or IoT
1. Pick one: a. Mobile apps: AWS Mobile SDK + Amazon Cognito (authorization) b. IoT devices: AWS IoT
2. AWS Lambda’s “Mobile Backend” blueprint 3. Amazon DynamoDB for data storage
AWS Lambda Amazon DynamoDB
![Page 28: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/28.jpg)
Principle of Complexity Concentration
jvm providers
Java compiler and tool providers
Java developers
![Page 29: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/29.jpg)
Principle of Complexity Concentration
Function hosting
Event and app ecosystems
Developers
![Page 30: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/30.jpg)
Amazon S3 Bucket Triggers
• Pick the S3 Lambda blueprint • Select your bucket as the event source
Amazon S3 bucket events
Original object Compressed object1
2
3
AWS Lambda
![Page 31: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/31.jpg)
Aside: Functions for Behavioral Abstraction
Amazon DynamoDB
Call Events
CustomizeA
PI
![Page 32: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/32.jpg)
Real-time Analytics Processing
1. Amazon Kinesis for high-speed data ingestion 2. Select AWS Lambda’s “Kinesis” blueprint 3. Store aggregated results in Amazon Redshift, Amazon S3,
Amazon DynamoDB
Data ingestion with Amazon Kinesis
(PUT record)
Records retrieved by AWS Lambda
Your code runs once per [batch of] records
Amazon S3
Amazon DynamoDB
smart devices
click stream
log data
Amazon Redshift
![Page 33: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/33.jpg)
How Work Arrives
• Synchronous calls (clients, APIs, cross-calls) • Asynchronous calls (example: Amazon S3) • Polling other services (example: Amazon Kinesis) • Schedules (“cron”) • If another service is involved, we call it an “event”
– Trivial programming model (IJJ – It’s Just JSON) – Operational complexity stays in the cloud, where it belongs:
• S3 and AWS Lambda handle impedance matching behind the scenes
![Page 34: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/34.jpg)
New App Ecosystems: Alexa Apps + Slack = Serverless Bots!
Alexa, tell Slack to send, “I’m giving the
demo now.”
Message Retrieval via scheduled pollingKevin says,
“Break a leg!”
Message Upload (via Slack API)
Team (channel users)
Slack
![Page 35: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/35.jpg)
SaaS and Enterprise Integration
![Page 36: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/36.jpg)
Customer Success Stories
![Page 37: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/37.jpg)
Pay-per Request
• Buy compute time in 100 ms increments
• Low request charge • No hourly, daily, or
monthly minimums • No per-device fees
Never pay for idle!
Free Tier
1 million requests and 400,000 GBs of compute
every month, every customer
![Page 38: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/38.jpg)
AWS Lambda, API Gateway, and AWS IoT Regions
Available regions
![Page 39: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/39.jpg)
Join the serverless revolution!
![Page 40: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/40.jpg)
Product manager or business analyst? Check out aws.amazon.com/lambda for scenarios and customer stories.
0.
![Page 41: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/41.jpg)
Developer? Go to the AWS Lambda console, create a function, and run it. (The first million invokes are on us!)
1.
![Page 42: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/42.jpg)
Congrats, you’re a Lambda function expert! Add an event source or an HTTP endpoint.2.
![Page 43: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/43.jpg)
Build a mobile, voice, or IoT backend with a few lines of code.3.
![Page 44: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/44.jpg)
Consign your devops tools to the dustbin of history.4.
![Page 45: Serverless Design Patterns with AWS Lambda (Philly ESE)](https://reader033.vdocuments.us/reader033/viewer/2022051319/58a1a20e1a28abf84d8c400f/html5/thumbnails/45.jpg)
Follow AWS Lambda and Amazon API Gateway!
aws.amazon.com/blogs/computeaws.amazon.com/lambdaAWS Lambda forum t: @timallenwagner