SlideShare a Scribd company logo
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Stephen Liedig
Solutions Architect, Public Sector ANZ
sliedig@amazon.com
May 5, 2017
Building Serverless Backends
Using AWS Lambda and Amazon API Gateway
Agenda
• Evolution of computing
• Serverless today
• Introduction to AWS Lambda
• Introduction to Amazon API Gateway
• Best practices
• Performance Tips
Let’s take a look at the evolution of computing
Physical Servers
in Datacenters
Virtual Servers
in Datacenters
Virtual Servers
in the Cloud
Each progressive step was better
Physical Servers
Datacenters
Virtual Servers
Datacenters
• Higher utilization
• Faster provisioning speed
• Improved uptime
• Disaster recovery
• Hardware independence
• Trade CAPEX for OPEX
• More scale
• Elastic resources
• Faster speed and agility
• Reduced maintenance
• Better availability and
fault tolerance
• Better Automation
Virtual Servers
in the Cloud
But there are still limitations
Physical Servers
Datacenters
Virtual Servers
Datacenters
• Trade CAPEX for OPEX
• More scale
• Elastic resources
• Faster speed and agility
• Reduced maintenance
• Better availability and
fault tolerance
• Still need to administer
virtual servers
• Still need to manage
capacity and utilization
• Still need to size
workloads
• Still need to manage
availability, fault tolerance
• Still expensive to run
intermittent jobs
Virtual Servers
in the Cloud
What is
serverless?
Build and run applications
without thinking about servers
“There is no server better than
no server”
– Werner Vogels, CTO Amazon
Serverless Today
Web
Applications
• Static
websites
• Complex web
apps
• Packages for
Flask and
Express
Data
Processing
• Real time
• MapReduce
• Batch
Chatbots
• Powering
chatbot logic
Backends
• Apps &
services
• Mobile
• IoT
</></>
Amazon
Alexa
• Powering
voice-enabled
apps
• Alexa Skills
Kit
Autonomous
IT
• Policy engines
• Extending
AWS services
• Infrastructure
management
Common use cases
Web Applications and Backends
Internet
Mobile Apps
Websites
Services
AWS Lambda
function
AWS
API Gateway
Cache
All publicly
accessible
endpoints
Amazon
CloudWatch
Monitoring
Amazon
CloudFront
Amazon	S3 AWS Lambda
function
AWS Lambda
function
Amazon DynamoDB
Web
Applications
• Static
websites
• Complex web
apps
• Packages for
Flask and
Express
Backends
• Apps &
services
• Mobile
• IoT
</></>
Common use cases
Data
Processing
• Real time
• MapReduce
• Batch
Data processing: Lambda + Kinesis
Common use cases
Data
Processing
• Real time
• MapReduce
• Batch
Data processing: Lambda + Dynamo DB
Common use cases
Web
Applications
• Static
websites
• Complex web
apps
• Packages for
Flask and
Express
Data
Processing
• Real time
• MapReduce
• Batch
Chatbots
• Powering
chatbot logic
Backends
• Apps &
services
• Mobile
• IoT
</></>
Amazon
Alexa
• Powering
voice-enabled
apps
• Alexa Skills
Kit
Autonomous
IT
• Policy engines
• Extending
AWS services
• Infrastructure
management
Common use cases
AWS Lambda
Zero-administration serverless
compute platform
AWS Lambda
Zero administration
• Focus on business logic, not infrastructure.
• Just upload your code, and AWS Lambda handles the rest.
Autoscaling
• AWS Lambda scales the infrastructure as needed to match
the event rate and pay as you go at 100ms intervals.
Bring your own code
• Code in Node.JS, Java, Python or C#.
• Create threads and processes, run batch scripts or other .exe files.
Sync and Async events
• Respond to application calls with low-latency real-time functions.
Cost-effective and
efficient
No Infrastructure
to manage
Pay only for what you use
Bring Your
Own Code
Productivity focused compute platform to build powerful, dynamic, modular
applications in the cloud
Run code in standard
languages
Focus on business logic
Benefits of AWS Lambda
1 2 3
Applications Components for Serverless apps
EVENT SOURCE FUNCTION SERVICES (ANYTHING)
Changes in
data state
Requests to
endpoints
Changes in
resource state
Node 4 / 6
Python 2 / 3
Java
C#
… more coming soon
Amazon S3 Amazon
DynamoDB
Amazon
Kinesis
AWS
CloudFormation
AWS
CloudTrail
Amazon
CloudWatch
Amazon SNSAmazon
SES
Amazon
API Gateway
Amazon
Cognito
AWS
IoT
Amazon
Alexa
Cron events
DATA STORES ENDPOINTS
REPOSITORIES EVENT/MESSAGE SERVICES
Event Sources that integrate with AWS Lambda
… and the list will continue to grow!
Amazon RDS
Aurora
Amazon API Gateway
Create, publish, maintain, monitor,
and secure APIs at any scale
Amazon API Gateway
Performance at any scale
• Uses AWS worldwide edge locations for low-latency API request/response,
distributed denial of service (DDoS) protection and integrated caching.
Run your APIs without servers
• Easily expose RESTful endpoints backed by Lambda for server-less APIs
for your enterprise, mobile and web applications.
Monitoring
• Visually monitor calls to your services using Amazon CloudWatch for
performance metrics.
Automation and definition
• Define your APIs using Swagger, CloudFormation or use CLI/SDKs
Amazon API Gateway
Versioning and deployment
• Host multiple versions and stages of your APIs.
Made for developers
• Create and distribute API keys to developers.
• Generate SDKs for iOS/Android and Javascript
Secure endpoint
• Leverage signature version 4 to authorize access to APIs.
Throttling and monitoring
• Throttle and monitor requests to protect your back end.
Benefits of Amazon API Gateway
Create a unified
API frontend for
multiple micro-
services
Authenticate and
authorize
requests to a
backend
DDoS protection
and throttling for
your backend
Throttle, meter,
and monetize API
usage by 3rd
party developers
The server-less stack
InternetMobile apps
AWS Lambda
functions
AWS
API Gateway
Other AWS
services
Managed
The server-less stack – zoom in
InternetMobile apps
AWS Lambda
functions
AWS
API Gateway
cache
Endpoints on
Amazon EC2
Any other publicly
accessible endpoint
Amazon
CloudWatch
Amazon
CloudFront
API
Gateway
API Gateway
Other AWS
services
AWS Lambda
functions
Best practices
Attaching Lambda functions to RESTful HTTP Endpoints
• 1:1 Mapping: Every API call triggers a stateless Lambda function
• Add caching to API calls to return a cached response instead for duplicate requests
• API Gateway concepts: An API is defined as a set of resources and methods
• Resource: A logical entity that can be accessed within an API
• Method: The combination of a resource path and an HTTP verb such as GET/POST
• Automatic Scaling: Both API Gateway and Lambda scale automatically with calls
• Safety throttle of 100 1000 concurrent Lambda functions, can be increased by AWS Support Center
• User defined standard-rate limit and a burst-rate limit per second for each API method
Best practices for creating Lambda functions
• Memory: CPU proportional to the memory configured
• Increasing memory makes your code execute faster (if CPU bound)
• Timeout: Increasing timeout allows for longer functions, but more wait in case of errors
• Retries: For API Gateway, Lambda doesn’t retry the function execution, but the
Gateway generated SDKs retry throttled requests
• Permission model: API Gateway synchronously triggers Lambda, so assign API
Gateway a resource policy to invoke Lambda.
Performance Tips
Optimizing Performance
Start-up
time
Optimized
resource
allocation
Code
optimization
Downstream
dependencies
Start-up time
Cold starts are real, but happen mostly in a dev environment
Cold start latency varies by the size of your function, the number of dependencies,
the runtime of your application (interpreted languages perform better)
Cold starts happen when:
• Developers use the console
• Edit the function
• Click test
VPC Integration will add overhead.
Memory and CPU
Think of memory as the “power” of the function. You increase memory
and AWS will proportionally increase # of vCPUs and networking
bandwidth allocated to the function.
Is your code CPU or memory-bound?
It could be cheaper to give more memory.
> Memory > Cores
1,526MB = XX Cores
Code Optimisation
AWS Lambda processes a single event per-container - only one event
will ever arrive at a time
• Parallelize as many event-processing tasks as possible once the
event is received (1024 threads)
Lazy load variables in the global scope
If you don’t need a response, invoke function
asynchronously on the client side.
Downstream Dependencies
Ensure you monitor your downstream dependencies for bottlenecks
and performance issues.
Watch for shared resources across functions.
Specify a realistic timeout value for your function.
Ensure they are idempotent
Remember, functions are stateless!
Next Steps
• Check out AWS LABS
https://github.com/awslabs/
• Try out the “Serverless Web-App Reference Architecture” at
https://github.com/awslabs/lambda-refarch-webapp/
• Check out some serverless frameworks:
1. https://github.com/awslabs/chalice (Python)
2. https://github.com/awslabs/aws-serverless-express (Express)
3. https://serverless.com/ (Serverless framework)
4. https://www.claudiajs.com (JS)
Thank you!

More Related Content

Similar to Building serverless backends - Tech talk 5 May 2017 (20)

PDF
Getting Started with AWS Lambda and Serverless Computing
Kristana Kane
 
PDF
Getting started building your first serverless web application on AWS
Ioannis Polyzos
 
PPTX
Building self service framework
Rovshan Musayev
 
PDF
Introduction to Serverless Computing and AWS Lambda - AWS IL Meetup
Boaz Ziniman
 
PDF
Serverless architectures-with-aws-lambda
saifam
 
PDF
Serverless use cases with AWS Lambda - More Serverless Event
Boaz Ziniman
 
PPTX
Getting started with Serverless on AWS
Adrian Hornsby
 
PPTX
Building API Driven Microservices
Chris Munns
 
PDF
Introduction to Serverless Computing - OOP Munich
Boaz Ziniman
 
PPTX
AWS Serverless with Lambda, ApiGateway
Ravi Soni
 
PPTX
The Future of Enterprise Applications is Serverless
Eficode
 
POTX
Serverless: State of The Union I AWS Dev Day 2018
AWS Germany
 
PDF
AWSomeDay Zurich 2018 - How to go serverless
Roman Plessl
 
PDF
Serverless Computing
Anand Gupta
 
PDF
Serverless on AWS: Architectural Patterns and Best Practices
Vladimir Simek
 
PDF
Čtvrtkon #64 - AWS Serverless - Michal Haták
Ctvrtkoncz
 
PDF
Serverless use cases with AWS Lambda
Boaz Ziniman
 
PDF
Infinite Scaling using Lambda and Aws - Atlogys Tech Talk
Atlogys Technical Consulting
 
PDF
What’s new in serverless - re:Invent 2020
AWS Chicago
 
PDF
Aws lambda webinar -buraku
burakunuvar
 
Getting Started with AWS Lambda and Serverless Computing
Kristana Kane
 
Getting started building your first serverless web application on AWS
Ioannis Polyzos
 
Building self service framework
Rovshan Musayev
 
Introduction to Serverless Computing and AWS Lambda - AWS IL Meetup
Boaz Ziniman
 
Serverless architectures-with-aws-lambda
saifam
 
Serverless use cases with AWS Lambda - More Serverless Event
Boaz Ziniman
 
Getting started with Serverless on AWS
Adrian Hornsby
 
Building API Driven Microservices
Chris Munns
 
Introduction to Serverless Computing - OOP Munich
Boaz Ziniman
 
AWS Serverless with Lambda, ApiGateway
Ravi Soni
 
The Future of Enterprise Applications is Serverless
Eficode
 
Serverless: State of The Union I AWS Dev Day 2018
AWS Germany
 
AWSomeDay Zurich 2018 - How to go serverless
Roman Plessl
 
Serverless Computing
Anand Gupta
 
Serverless on AWS: Architectural Patterns and Best Practices
Vladimir Simek
 
Čtvrtkon #64 - AWS Serverless - Michal Haták
Ctvrtkoncz
 
Serverless use cases with AWS Lambda
Boaz Ziniman
 
Infinite Scaling using Lambda and Aws - Atlogys Tech Talk
Atlogys Technical Consulting
 
What’s new in serverless - re:Invent 2020
AWS Chicago
 
Aws lambda webinar -buraku
burakunuvar
 

More from ARDC (20)

PPTX
Introduction to ADA
ARDC
 
PPTX
Architecture and Standards
ARDC
 
PPTX
Data Sharing and Release Legislation
ARDC
 
PPT
Australian Dementia Network (ADNet)
ARDC
 
PPTX
Investigator-initiated clinical trials: a community perspective
ARDC
 
PPTX
NCRIS and the health domain
ARDC
 
PPTX
International perspective for sharing publicly funded medical research data
ARDC
 
PPTX
Clinical trials data sharing
ARDC
 
PPTX
Clinical trials and cohort studies
ARDC
 
PPTX
Introduction to vision and scope
ARDC
 
PPTX
FAIR for the future: embracing all things data
ARDC
 
PDF
ARDC 2018 state engagements - Nov-Dec 2018 - Slides - Ian Duncan
ARDC
 
PDF
Skilling-up-in-research-data-management-20181128
ARDC
 
PDF
Research data management and sharing of medical data
ARDC
 
PPTX
Findable, Accessible, Interoperable and Reusable (FAIR) data
ARDC
 
PPTX
Applying FAIR principles to linked datasets: Opportunities and Challenges
ARDC
 
PDF
How to make your data count webinar, 26 Nov 2018
ARDC
 
PDF
Ready, Set, Go! Join the Top 10 FAIR Data Things Global Sprint
ARDC
 
PDF
How FAIR is your data? Copyright, licensing and reuse of data
ARDC
 
PDF
Peter neish DMPs BoF eResearch 2018
ARDC
 
Introduction to ADA
ARDC
 
Architecture and Standards
ARDC
 
Data Sharing and Release Legislation
ARDC
 
Australian Dementia Network (ADNet)
ARDC
 
Investigator-initiated clinical trials: a community perspective
ARDC
 
NCRIS and the health domain
ARDC
 
International perspective for sharing publicly funded medical research data
ARDC
 
Clinical trials data sharing
ARDC
 
Clinical trials and cohort studies
ARDC
 
Introduction to vision and scope
ARDC
 
FAIR for the future: embracing all things data
ARDC
 
ARDC 2018 state engagements - Nov-Dec 2018 - Slides - Ian Duncan
ARDC
 
Skilling-up-in-research-data-management-20181128
ARDC
 
Research data management and sharing of medical data
ARDC
 
Findable, Accessible, Interoperable and Reusable (FAIR) data
ARDC
 
Applying FAIR principles to linked datasets: Opportunities and Challenges
ARDC
 
How to make your data count webinar, 26 Nov 2018
ARDC
 
Ready, Set, Go! Join the Top 10 FAIR Data Things Global Sprint
ARDC
 
How FAIR is your data? Copyright, licensing and reuse of data
ARDC
 
Peter neish DMPs BoF eResearch 2018
ARDC
 
Ad

Recently uploaded (20)

PDF
Carbonate formation and fluctuating habitability on Mars
Sérgio Sacani
 
DOCX
Paper - Taboo Language (Makalah Presentasi)
Sahmiral Amri Rajagukguk
 
PDF
Adding Geochemistry To Understand Recharge Areas - Kinney County, Texas - Jim...
Texas Alliance of Groundwater Districts
 
PPTX
Q1 - W1 - D2 - Models of matter for science.pptx
RyanCudal3
 
PPTX
Neuroinflammation and microglial subtypes
KanakChaudhary10
 
PDF
EXploring Nanobiotechnology: Bridging Nanoscience and Biology for real world ...
Aamena3
 
PPTX
CNS.pptx Central nervous system meninges ventricles of brain it's structure a...
Ashwini I Chuncha
 
PDF
Annual report 2024 - Inria - English version.pdf
Inria
 
PDF
Global Congress on Forensic Science and Research
infoforensicscience2
 
PPTX
Renewable Energy Resources - Introduction
BhajneetSingh1
 
PPTX
Bacillus thuringiensis.crops & golden rice
priyadharshini87125
 
PDF
Webinar: World's Smallest Pacemaker
Scintica Instrumentation
 
PDF
The emergence of galactic thin and thick discs across cosmic history
Sérgio Sacani
 
PDF
Rapid protoplanet formation in the outer Solar System recorded in a dunite fr...
Sérgio Sacani
 
PDF
20250603 Recycling 4.pdf . Rice flour, aluminium, hydrogen, paper, cardboard.
Sharon Liu
 
DOCX
Analytical methods in CleaningValidation.docx
Markus Janssen
 
PDF
Integrating Lifestyle Data into Personalized Health Solutions (www.kiu.ac.ug)
publication11
 
PDF
A Man of the Forest: The Contributions of Gifford Pinchot
RowanSales
 
PDF
Carbon-richDustInjectedintotheInterstellarMediumbyGalacticWCBinaries Survives...
Sérgio Sacani
 
PPTX
Diagnostic Features of Common Oral Ulcerative Lesions.pptx
Dr Palak borade
 
Carbonate formation and fluctuating habitability on Mars
Sérgio Sacani
 
Paper - Taboo Language (Makalah Presentasi)
Sahmiral Amri Rajagukguk
 
Adding Geochemistry To Understand Recharge Areas - Kinney County, Texas - Jim...
Texas Alliance of Groundwater Districts
 
Q1 - W1 - D2 - Models of matter for science.pptx
RyanCudal3
 
Neuroinflammation and microglial subtypes
KanakChaudhary10
 
EXploring Nanobiotechnology: Bridging Nanoscience and Biology for real world ...
Aamena3
 
CNS.pptx Central nervous system meninges ventricles of brain it's structure a...
Ashwini I Chuncha
 
Annual report 2024 - Inria - English version.pdf
Inria
 
Global Congress on Forensic Science and Research
infoforensicscience2
 
Renewable Energy Resources - Introduction
BhajneetSingh1
 
Bacillus thuringiensis.crops & golden rice
priyadharshini87125
 
Webinar: World's Smallest Pacemaker
Scintica Instrumentation
 
The emergence of galactic thin and thick discs across cosmic history
Sérgio Sacani
 
Rapid protoplanet formation in the outer Solar System recorded in a dunite fr...
Sérgio Sacani
 
20250603 Recycling 4.pdf . Rice flour, aluminium, hydrogen, paper, cardboard.
Sharon Liu
 
Analytical methods in CleaningValidation.docx
Markus Janssen
 
Integrating Lifestyle Data into Personalized Health Solutions (www.kiu.ac.ug)
publication11
 
A Man of the Forest: The Contributions of Gifford Pinchot
RowanSales
 
Carbon-richDustInjectedintotheInterstellarMediumbyGalacticWCBinaries Survives...
Sérgio Sacani
 
Diagnostic Features of Common Oral Ulcerative Lesions.pptx
Dr Palak borade
 
Ad

Building serverless backends - Tech talk 5 May 2017

  • 1. © 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Stephen Liedig Solutions Architect, Public Sector ANZ [email protected] May 5, 2017 Building Serverless Backends Using AWS Lambda and Amazon API Gateway
  • 2. Agenda • Evolution of computing • Serverless today • Introduction to AWS Lambda • Introduction to Amazon API Gateway • Best practices • Performance Tips
  • 3. Let’s take a look at the evolution of computing Physical Servers in Datacenters Virtual Servers in Datacenters Virtual Servers in the Cloud
  • 4. Each progressive step was better Physical Servers Datacenters Virtual Servers Datacenters • Higher utilization • Faster provisioning speed • Improved uptime • Disaster recovery • Hardware independence • Trade CAPEX for OPEX • More scale • Elastic resources • Faster speed and agility • Reduced maintenance • Better availability and fault tolerance • Better Automation Virtual Servers in the Cloud
  • 5. But there are still limitations Physical Servers Datacenters Virtual Servers Datacenters • Trade CAPEX for OPEX • More scale • Elastic resources • Faster speed and agility • Reduced maintenance • Better availability and fault tolerance • Still need to administer virtual servers • Still need to manage capacity and utilization • Still need to size workloads • Still need to manage availability, fault tolerance • Still expensive to run intermittent jobs Virtual Servers in the Cloud
  • 6. What is serverless? Build and run applications without thinking about servers
  • 7. “There is no server better than no server” – Werner Vogels, CTO Amazon
  • 9. Web Applications • Static websites • Complex web apps • Packages for Flask and Express Data Processing • Real time • MapReduce • Batch Chatbots • Powering chatbot logic Backends • Apps & services • Mobile • IoT </></> Amazon Alexa • Powering voice-enabled apps • Alexa Skills Kit Autonomous IT • Policy engines • Extending AWS services • Infrastructure management Common use cases
  • 10. Web Applications and Backends Internet Mobile Apps Websites Services AWS Lambda function AWS API Gateway Cache All publicly accessible endpoints Amazon CloudWatch Monitoring Amazon CloudFront Amazon S3 AWS Lambda function AWS Lambda function Amazon DynamoDB Web Applications • Static websites • Complex web apps • Packages for Flask and Express Backends • Apps & services • Mobile • IoT </></> Common use cases
  • 11. Data Processing • Real time • MapReduce • Batch Data processing: Lambda + Kinesis Common use cases
  • 12. Data Processing • Real time • MapReduce • Batch Data processing: Lambda + Dynamo DB Common use cases
  • 13. Web Applications • Static websites • Complex web apps • Packages for Flask and Express Data Processing • Real time • MapReduce • Batch Chatbots • Powering chatbot logic Backends • Apps & services • Mobile • IoT </></> Amazon Alexa • Powering voice-enabled apps • Alexa Skills Kit Autonomous IT • Policy engines • Extending AWS services • Infrastructure management Common use cases
  • 15. AWS Lambda Zero administration • Focus on business logic, not infrastructure. • Just upload your code, and AWS Lambda handles the rest. Autoscaling • AWS Lambda scales the infrastructure as needed to match the event rate and pay as you go at 100ms intervals. Bring your own code • Code in Node.JS, Java, Python or C#. • Create threads and processes, run batch scripts or other .exe files. Sync and Async events • Respond to application calls with low-latency real-time functions.
  • 16. Cost-effective and efficient No Infrastructure to manage Pay only for what you use Bring Your Own Code Productivity focused compute platform to build powerful, dynamic, modular applications in the cloud Run code in standard languages Focus on business logic Benefits of AWS Lambda 1 2 3
  • 17. Applications Components for Serverless apps EVENT SOURCE FUNCTION SERVICES (ANYTHING) Changes in data state Requests to endpoints Changes in resource state Node 4 / 6 Python 2 / 3 Java C# … more coming soon
  • 18. Amazon S3 Amazon DynamoDB Amazon Kinesis AWS CloudFormation AWS CloudTrail Amazon CloudWatch Amazon SNSAmazon SES Amazon API Gateway Amazon Cognito AWS IoT Amazon Alexa Cron events DATA STORES ENDPOINTS REPOSITORIES EVENT/MESSAGE SERVICES Event Sources that integrate with AWS Lambda … and the list will continue to grow! Amazon RDS Aurora
  • 19. Amazon API Gateway Create, publish, maintain, monitor, and secure APIs at any scale
  • 20. Amazon API Gateway Performance at any scale • Uses AWS worldwide edge locations for low-latency API request/response, distributed denial of service (DDoS) protection and integrated caching. Run your APIs without servers • Easily expose RESTful endpoints backed by Lambda for server-less APIs for your enterprise, mobile and web applications. Monitoring • Visually monitor calls to your services using Amazon CloudWatch for performance metrics. Automation and definition • Define your APIs using Swagger, CloudFormation or use CLI/SDKs
  • 21. Amazon API Gateway Versioning and deployment • Host multiple versions and stages of your APIs. Made for developers • Create and distribute API keys to developers. • Generate SDKs for iOS/Android and Javascript Secure endpoint • Leverage signature version 4 to authorize access to APIs. Throttling and monitoring • Throttle and monitor requests to protect your back end.
  • 22. Benefits of Amazon API Gateway Create a unified API frontend for multiple micro- services Authenticate and authorize requests to a backend DDoS protection and throttling for your backend Throttle, meter, and monetize API usage by 3rd party developers
  • 23. The server-less stack InternetMobile apps AWS Lambda functions AWS API Gateway Other AWS services
  • 24. Managed The server-less stack – zoom in InternetMobile apps AWS Lambda functions AWS API Gateway cache Endpoints on Amazon EC2 Any other publicly accessible endpoint Amazon CloudWatch Amazon CloudFront API Gateway API Gateway Other AWS services AWS Lambda functions
  • 26. Attaching Lambda functions to RESTful HTTP Endpoints • 1:1 Mapping: Every API call triggers a stateless Lambda function • Add caching to API calls to return a cached response instead for duplicate requests • API Gateway concepts: An API is defined as a set of resources and methods • Resource: A logical entity that can be accessed within an API • Method: The combination of a resource path and an HTTP verb such as GET/POST • Automatic Scaling: Both API Gateway and Lambda scale automatically with calls • Safety throttle of 100 1000 concurrent Lambda functions, can be increased by AWS Support Center • User defined standard-rate limit and a burst-rate limit per second for each API method
  • 27. Best practices for creating Lambda functions • Memory: CPU proportional to the memory configured • Increasing memory makes your code execute faster (if CPU bound) • Timeout: Increasing timeout allows for longer functions, but more wait in case of errors • Retries: For API Gateway, Lambda doesn’t retry the function execution, but the Gateway generated SDKs retry throttled requests • Permission model: API Gateway synchronously triggers Lambda, so assign API Gateway a resource policy to invoke Lambda.
  • 30. Start-up time Cold starts are real, but happen mostly in a dev environment Cold start latency varies by the size of your function, the number of dependencies, the runtime of your application (interpreted languages perform better) Cold starts happen when: • Developers use the console • Edit the function • Click test VPC Integration will add overhead.
  • 31. Memory and CPU Think of memory as the “power” of the function. You increase memory and AWS will proportionally increase # of vCPUs and networking bandwidth allocated to the function. Is your code CPU or memory-bound? It could be cheaper to give more memory. > Memory > Cores 1,526MB = XX Cores
  • 32. Code Optimisation AWS Lambda processes a single event per-container - only one event will ever arrive at a time • Parallelize as many event-processing tasks as possible once the event is received (1024 threads) Lazy load variables in the global scope If you don’t need a response, invoke function asynchronously on the client side.
  • 33. Downstream Dependencies Ensure you monitor your downstream dependencies for bottlenecks and performance issues. Watch for shared resources across functions. Specify a realistic timeout value for your function. Ensure they are idempotent Remember, functions are stateless!
  • 34. Next Steps • Check out AWS LABS https://github.com/awslabs/ • Try out the “Serverless Web-App Reference Architecture” at https://github.com/awslabs/lambda-refarch-webapp/ • Check out some serverless frameworks: 1. https://github.com/awslabs/chalice (Python) 2. https://github.com/awslabs/aws-serverless-express (Express) 3. https://serverless.com/ (Serverless framework) 4. https://www.claudiajs.com (JS)