SlideShare a Scribd company logo
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
© 2022, Amazon Web Services, Inc. or its affiliates.
AWS Lambda
Deep Dive
Dhiraj Mahapatro
Principal Specialist SA, Serverless
AWS
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Agenda
• What is AWS Lambda?
• Lambda invocation modes
• The Execution Environment
• Other notable features
• Quotas & best practices
2
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
© 2022, Amazon Web Services, Inc. or its affiliates.
What is
AWS Lambda?
3
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
The high-level view
4
Events
AWS Services
Databases
Etc.
Python
Javascript
Java
C#
Golang
BYOL
Container images
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
The customer view
5
IAM or Lambda
Permissions
Event Source
Mapping
AWS Lambda
Functions
IAM Execution
Role
Execution
Environments
Execution
Environments
Alias: Prod Alias: Stage
Version 1 Version 2
Code Config
Zip + Layers
Container images 80% 100%
20%
or
and more
and more
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
AWS Lambda under the hood
6
Event Source
Mapping
AWS Lambda
or
and more
and more
Internal
Queue
Workers
microVM microVM
microVM microVM
Sandbox Sandbox
Sandbox
Sandbox
Sync
Async
Frontend
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
© 2022, Amazon Web Services, Inc. or its affiliates.
Lambda
invocation modes
7
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Lambda invocation modes
8
Event Source
Mapping
Internal
Queue
Sync
Async
Frontend
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
When the caller expects a
response from the function.
Three invocation modes
Synchronous Asynchronous
When the caller doesn't expect
a response from the function.
Event Source Mapping
Integration with specific event
sources.
(Synchronous under the hood)
9
event
response
event
Internal queue
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Synchronous invocation mode
10
or
and more
microVM
Sandbox
Sync
Frontend
• Useful when you need an immediate response
from the function.
• Errors are returned to the caller.
• Returns throttles when you hit the concurrency
limit.
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Asynchronous invocation mode
11
or
and more
Internal
Queue
microVM
Sandbox
Async
Frontend
• Caller only gets an acknowledgement from the
Lambda service.
• Internal queue that can persist messages for up
to 6 hours.
• Support retries (up to 2 retries, or 3 invokes
total), destinations and DLQ.
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Event Source Mapping
12
Event Source
Mapping
and more
microVM
Sandbox
Frontend
• Event Source Mapping pulls messages from the
source, then does synchronous invokes.
• Can do batching, error handling, and more. The
exact capabilities differ by event source.
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
© 2022, Amazon Web Services, Inc. or its affiliates.
The Lambda Execution
Environment
(a.k.a. Sandbox)
13
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Lambda execution environments
14
Workers
microVM microVM
microVM microVM
Sandbox Sandbox
Sandbox
Sandbox
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Lambda execution environments
15
Workers
microVM microVM
microVM microVM
Sandbox Sandbox
Sandbox
Sandbox
• Execution Environment (EE): where your code
actually runs. One EE handles one request at a
time.
• Concurrency: number of EEs actively serving
traffic for a given Function/Version/Alias.
Concurrency ≈ RPS × Duration
Concurrency ≤ number of EEs
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Execution environment lifecycle
16
Execution
Environment
Initialization
Invoke
Invoke
Invoke
Invoke
Invoke
Shutdown
Initialization
Execution
Environment
Invoke
Invoke
Shutdown
Time
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Measuring Lambda concurrency
Concurrency = TPS * Duration (in seconds)
TPS = 100
Duration = 500 ms or ½ second
Concurrency
100 * (500/1000) = 50
TPS = 100
Duration = 2,000 ms or 2 seconds
Concurrency
100 * (2) = 200
Optimize for durations < 1 second
Monitor ConcurrentExecutions Metric
17
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Sizing the Execution Environment
More memory
=
more CPU resources
From 128MB to 10GB
Up to 6 vCPUs
18
https://github.com/alexcasalboni/aws-lambda-power-
tuning
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Understanding Lambda performance
CloudWatch Logs Insights query that
breaks down cold start and warm
start performances at different
percentiles.
filter @type="REPORT"
| fields
greatest(@initDuration, 0) +
@duration as duration,
ispresent(@initDuration)
as coldStart
| stats count(*) as count,
pct(duration, 50) as p50,
pct(duration, 90) as p90,
pct(duration, 99) as p99,
max(duration) as max by coldStart
19
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
CPU Architectures
Two architecture options:
• x86_64
• Arm64 (powered by graviton2)
Why Arm64?
Up to 19% better performance, and 20%
lower cost.
Things to keep in mind
Binaries need to be compiled for Arm64.
Some libraries/tools might not be
optimized for Arm64 yet.
20
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
© 2022, Amazon Web Services, Inc. or its affiliates.
Other
notable features
21
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Other notable features
Lambda Function URL
Create & configure dedicated HTTPS endpoint
for your Lambda function.
Amazon EFS Integration
Mount an EFS file system to a local directory.
Code Signing
Ensure only trusted code runs in your Lambda
functions.
Up to 10GB Ephemeral Storage
Configure /tmp storage between 512MB and 10GB.
Amazon RDS Proxy
Pool database connections to reach high concurrency
without exhausting DB connections.
22
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
© 2022, Amazon Web Services, Inc. or its affiliates.
Quotas &
best practices
23
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Important quotas
• Concurrent executions: 1000, can be increased to hundreds of thousands
• Burst capacity limit: 500-3000, hard limit
• Invocation payload: 6MB sync, 256KB async
• Deployment package:
• Zip file: 50MB zipped, 250MB unzipped
• Container image: 10GB
• Temporary storage: 512MB – Free (can go up to 10GB with additional cost)
• Invocations per second:
• Sync/Async non-AWS: 10x concurrent execution quota
• Async AWS: unlimited
• Provisioned concurrency: 10x provisioned concurrency
• ENIs per VPC: 100
24
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
AWS Lambda Powertools
• Tracing with AWS X-Ray
For end-to-end observability
• Structured logging
for search and aggregation
• Custom metrics
with CloudWatch Logs EMF
Python:
https://github.com/awslabs/aws-lambda-
powertools-python
Java:
https://github.com/awslabs/aws-lambda-
powertools-java
Typescript:
https://github.com/awslabs/aws-lambda-
powertools-typescript
25
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Error handling
Synchronous:
The function returns an error to the caller.
Asynchronous:
Configure destination on the function to alert
and store failures.
Event Source Mapping (SQS):
Setup a dead-letter queue (DLQ) on the queue.
Event Source Mapping (other sources):
Configure destination on the event source mapping
to alert and store failures.
26
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Function optimizations
• Take advantage of EE reuse by initializing
resources outside of the function handler.
• Minimize the size of your deployment
package to its runtime necessities.
• Opt for dependencies that load quickly when
possible.
27
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Well-Architected Framework
Serverless Lens:
Well-architected questions and guidance for
serverless workloads.
https://docs.aws.amazon.com/
wellarchitected/latest/serverless-applications-
lens/welcome.html
Serverless Rules:
Infrastructure-as-code linter to validate against
best practices. E.g.:
• Function with tracing disabled
• Asynchronous function without failure
destination
https://github.com/aws-
samples/serverless-rules
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Serverless demos in various languages
Go
https://github.com/aws-samples/serverless-go-
demo
Groovy
https://github.com/aws-samples/serverless-
groovy-demo
Java (GraalVM)
https://github.com/aws-samples/serverless-
graalvm-demo
Kotlin
https://github.com/aws-samples/serverless-
kotlin-demo
Micronaut/Quarkus/SpringBoot
https://github.com/aws-samples/serverless-
java-frameworks-samples
.NET
https://github.com/aws-samples/serverless-
dotnet-demo
Rust
https://github.com/aws-
samples/serverless-rust-demo
Typescript
https://github.com/aws-
samples/serverless-typescript-demo
29
AWS LAMBDA DEEP DIVE
© 2022, Amazon Web Services, Inc. or its affiliates.
Thank you!
© 2022, Amazon Web Services, Inc. or its affiliates. 30
Dhiraj Mahapatro
mahadhir@amazon.com
Twitter: @dhirajmahapatro
LinkedIn: dmahapatro

More Related Content

What's hot (20)

ODP
An Introduction To Jenkins
Knoldus Inc.
 
PPTX
Application performance monitoring with Elastic APM and the ELK stack
Alain Lompo
 
PPTX
DevSecOps reference architectures 2018
Sonatype
 
PDF
DevSecOps and the CI/CD Pipeline
James Wickett
 
PPT
Unit 7
anuragmbst
 
PDF
DevOps Powerpoint Presentation Slides
SlideTeam
 
PPTX
API as-a-Product with Azure API Management (APIM)
Bishoy Demian
 
PPTX
6 types of web application development
Clustox
 
PDF
CI/CD with Github Actions
Md. Minhazul Haque
 
PPTX
DevOps 101 - an Introduction to DevOps
Red Gate Software
 
PDF
Introduction to CICD
Knoldus Inc.
 
PPTX
Github in Action
Morten Christensen
 
PDF
DevOps
ARYA TM
 
PDF
APIsecure 2023 - Exploring Advanced API Security Techniques and Technologies,...
apidays
 
PDF
penetration test using Kali linux seminar report
AbhayNaik8
 
PPTX
DevOps introduction
Mettje Heegstra
 
PPT
presentation on Docker
Virendra Ruhela
 
An Introduction To Jenkins
Knoldus Inc.
 
Application performance monitoring with Elastic APM and the ELK stack
Alain Lompo
 
DevSecOps reference architectures 2018
Sonatype
 
DevSecOps and the CI/CD Pipeline
James Wickett
 
Unit 7
anuragmbst
 
DevOps Powerpoint Presentation Slides
SlideTeam
 
API as-a-Product with Azure API Management (APIM)
Bishoy Demian
 
6 types of web application development
Clustox
 
CI/CD with Github Actions
Md. Minhazul Haque
 
DevOps 101 - an Introduction to DevOps
Red Gate Software
 
Introduction to CICD
Knoldus Inc.
 
Github in Action
Morten Christensen
 
DevOps
ARYA TM
 
APIsecure 2023 - Exploring Advanced API Security Techniques and Technologies,...
apidays
 
penetration test using Kali linux seminar report
AbhayNaik8
 
DevOps introduction
Mettje Heegstra
 
presentation on Docker
Virendra Ruhela
 

Similar to AWS Community Day 2022 Dhiraj Mahapatro_AWS Lambda under the hood _ Best Practices (20)

PDF
What’s new in serverless - re:Invent 2020
AWS Chicago
 
PDF
AWS re:Invent 2020 Serverless Recap
Daniel Zivkovic
 
PDF
AWS Lambda Functions A Comprehensive Guide
Inexture Solutions
 
PDF
Getting started building your first serverless web application on AWS
Ioannis Polyzos
 
PPTX
AWS Lambda Features and Uses
GlobalLogic Ukraine
 
PDF
What's new in Serverless at AWS?
Daniel Zivkovic
 
PDF
Getting Started with AWS Lambda & Serverless Cloud
Ian Massingham
 
PDF
Serverless on AWS: Architectural Patterns and Best Practices
Vladimir Simek
 
PPTX
Getting Started with Serverless Architectures
AWS Summits
 
PDF
A quick introduction to AWS Lambda
ogeisser
 
PPTX
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
Chris Munns
 
PPTX
AWS Serverless Computing Introduction Session 2.pptx
krnaween
 
PDF
Intro to AWS Lambda
Sandra Garcia
 
PDF
AWS Lambda Deep Dive
Alfonso Cabrera
 
PDF
AWS Lambda: Best Practices and Common Mistakes - DevOps East 2019
Derek Ashmore
 
PPTX
Containerless in the Cloud with AWS Lambda
Ryan Cuprak
 
PPTX
Getting started with Serverless on AWS
Adrian Hornsby
 
PDF
Overview aws-lambda-security
mustafa sarac
 
PDF
The Best Practices and Hard Lessons Learned of Serverless Applications
Amazon Web Services LATAM
 
PDF
AWS Lambda
Alexander Savchuk
 
What’s new in serverless - re:Invent 2020
AWS Chicago
 
AWS re:Invent 2020 Serverless Recap
Daniel Zivkovic
 
AWS Lambda Functions A Comprehensive Guide
Inexture Solutions
 
Getting started building your first serverless web application on AWS
Ioannis Polyzos
 
AWS Lambda Features and Uses
GlobalLogic Ukraine
 
What's new in Serverless at AWS?
Daniel Zivkovic
 
Getting Started with AWS Lambda & Serverless Cloud
Ian Massingham
 
Serverless on AWS: Architectural Patterns and Best Practices
Vladimir Simek
 
Getting Started with Serverless Architectures
AWS Summits
 
A quick introduction to AWS Lambda
ogeisser
 
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
Chris Munns
 
AWS Serverless Computing Introduction Session 2.pptx
krnaween
 
Intro to AWS Lambda
Sandra Garcia
 
AWS Lambda Deep Dive
Alfonso Cabrera
 
AWS Lambda: Best Practices and Common Mistakes - DevOps East 2019
Derek Ashmore
 
Containerless in the Cloud with AWS Lambda
Ryan Cuprak
 
Getting started with Serverless on AWS
Adrian Hornsby
 
Overview aws-lambda-security
mustafa sarac
 
The Best Practices and Hard Lessons Learned of Serverless Applications
Amazon Web Services LATAM
 
AWS Lambda
Alexander Savchuk
 
Ad

More from AWS Chicago (20)

PDF
AWS Community Day Midwest 2025 Julia Furst Morgado The Lazy Guide to Kuberne...
AWS Chicago
 
PDF
Steven Seaney - Simplifying and Streamlining AWS Control Tower Deployments
AWS Chicago
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PPTX
Paul Chin Jr. Data Gone in 60 Seconds: A Serverless ETL Heist
AWS Chicago
 
PPTX
Abubakar Abdikadir - Driving AWS Savings Through Visibility and Automation
AWS Chicago
 
PPTX
Andy Hall - Build verifiable explainability into financial services workflow...
AWS Chicago
 
PPTX
Alec MacEachern - Scaling Enterprise Agents
AWS Chicago
 
PPTX
Alex Gottemoller - Recreating Moviephone in 30 Min
AWS Chicago
 
PDF
Dakota Riley - 10 Fun Facts to Level Up Your Boto3 Game!
AWS Chicago
 
PPTX
From SQL Server to Aurora PostgreSQL: A Migration Story
AWS Chicago
 
PDF
Edwin Moedano - Monitoring and Observability of Lambdas with Cloudwatch and P...
AWS Chicago
 
PPTX
Alec MacEachern - Scaling Enterprise Agents
AWS Chicago
 
PDF
Ben Blair - Operating Safely in a Vibe Coding World
AWS Chicago
 
PPTX
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and ...
AWS Chicago
 
PDF
Steven Seaney - Simplifying and Streamlining AWS Control Tower Deployments
AWS Chicago
 
PPTX
Alex Gottemoller - Recreating Moviephone in 30 Min
AWS Chicago
 
PPTX
Abubakar Abdikadir - Driving AWS Savings Through Visibility and Automation
AWS Chicago
 
PPTX
Nathan Hiscock - Architecting secure, scalable, cost-efficient computer visio...
AWS Chicago
 
PPTX
Andy Hall Build verifiable explainability into financial services workflows w...
AWS Chicago
 
PDF
Chicago AWS Architectural Resilience Day 2024
AWS Chicago
 
AWS Community Day Midwest 2025 Julia Furst Morgado The Lazy Guide to Kuberne...
AWS Chicago
 
Steven Seaney - Simplifying and Streamlining AWS Control Tower Deployments
AWS Chicago
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Paul Chin Jr. Data Gone in 60 Seconds: A Serverless ETL Heist
AWS Chicago
 
Abubakar Abdikadir - Driving AWS Savings Through Visibility and Automation
AWS Chicago
 
Andy Hall - Build verifiable explainability into financial services workflow...
AWS Chicago
 
Alec MacEachern - Scaling Enterprise Agents
AWS Chicago
 
Alex Gottemoller - Recreating Moviephone in 30 Min
AWS Chicago
 
Dakota Riley - 10 Fun Facts to Level Up Your Boto3 Game!
AWS Chicago
 
From SQL Server to Aurora PostgreSQL: A Migration Story
AWS Chicago
 
Edwin Moedano - Monitoring and Observability of Lambdas with Cloudwatch and P...
AWS Chicago
 
Alec MacEachern - Scaling Enterprise Agents
AWS Chicago
 
Ben Blair - Operating Safely in a Vibe Coding World
AWS Chicago
 
Darren Mills The Migration Modernization Balancing Act: Navigating Risks and ...
AWS Chicago
 
Steven Seaney - Simplifying and Streamlining AWS Control Tower Deployments
AWS Chicago
 
Alex Gottemoller - Recreating Moviephone in 30 Min
AWS Chicago
 
Abubakar Abdikadir - Driving AWS Savings Through Visibility and Automation
AWS Chicago
 
Nathan Hiscock - Architecting secure, scalable, cost-efficient computer visio...
AWS Chicago
 
Andy Hall Build verifiable explainability into financial services workflows w...
AWS Chicago
 
Chicago AWS Architectural Resilience Day 2024
AWS Chicago
 
Ad

Recently uploaded (20)

PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Python basic programing language for automation
DanialHabibi2
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 

AWS Community Day 2022 Dhiraj Mahapatro_AWS Lambda under the hood _ Best Practices

  • 1. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. AWS Lambda Deep Dive Dhiraj Mahapatro Principal Specialist SA, Serverless AWS
  • 2. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Agenda • What is AWS Lambda? • Lambda invocation modes • The Execution Environment • Other notable features • Quotas & best practices 2
  • 3. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. What is AWS Lambda? 3
  • 4. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. The high-level view 4 Events AWS Services Databases Etc. Python Javascript Java C# Golang BYOL Container images
  • 5. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. The customer view 5 IAM or Lambda Permissions Event Source Mapping AWS Lambda Functions IAM Execution Role Execution Environments Execution Environments Alias: Prod Alias: Stage Version 1 Version 2 Code Config Zip + Layers Container images 80% 100% 20% or and more and more
  • 6. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. AWS Lambda under the hood 6 Event Source Mapping AWS Lambda or and more and more Internal Queue Workers microVM microVM microVM microVM Sandbox Sandbox Sandbox Sandbox Sync Async Frontend
  • 7. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. Lambda invocation modes 7
  • 8. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Lambda invocation modes 8 Event Source Mapping Internal Queue Sync Async Frontend
  • 9. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. When the caller expects a response from the function. Three invocation modes Synchronous Asynchronous When the caller doesn't expect a response from the function. Event Source Mapping Integration with specific event sources. (Synchronous under the hood) 9 event response event Internal queue
  • 10. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Synchronous invocation mode 10 or and more microVM Sandbox Sync Frontend • Useful when you need an immediate response from the function. • Errors are returned to the caller. • Returns throttles when you hit the concurrency limit.
  • 11. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Asynchronous invocation mode 11 or and more Internal Queue microVM Sandbox Async Frontend • Caller only gets an acknowledgement from the Lambda service. • Internal queue that can persist messages for up to 6 hours. • Support retries (up to 2 retries, or 3 invokes total), destinations and DLQ.
  • 12. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Event Source Mapping 12 Event Source Mapping and more microVM Sandbox Frontend • Event Source Mapping pulls messages from the source, then does synchronous invokes. • Can do batching, error handling, and more. The exact capabilities differ by event source.
  • 13. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. The Lambda Execution Environment (a.k.a. Sandbox) 13
  • 14. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Lambda execution environments 14 Workers microVM microVM microVM microVM Sandbox Sandbox Sandbox Sandbox
  • 15. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Lambda execution environments 15 Workers microVM microVM microVM microVM Sandbox Sandbox Sandbox Sandbox • Execution Environment (EE): where your code actually runs. One EE handles one request at a time. • Concurrency: number of EEs actively serving traffic for a given Function/Version/Alias. Concurrency ≈ RPS × Duration Concurrency ≤ number of EEs
  • 16. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Execution environment lifecycle 16 Execution Environment Initialization Invoke Invoke Invoke Invoke Invoke Shutdown Initialization Execution Environment Invoke Invoke Shutdown Time
  • 17. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Measuring Lambda concurrency Concurrency = TPS * Duration (in seconds) TPS = 100 Duration = 500 ms or ½ second Concurrency 100 * (500/1000) = 50 TPS = 100 Duration = 2,000 ms or 2 seconds Concurrency 100 * (2) = 200 Optimize for durations < 1 second Monitor ConcurrentExecutions Metric 17
  • 18. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Sizing the Execution Environment More memory = more CPU resources From 128MB to 10GB Up to 6 vCPUs 18 https://github.com/alexcasalboni/aws-lambda-power- tuning
  • 19. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Understanding Lambda performance CloudWatch Logs Insights query that breaks down cold start and warm start performances at different percentiles. filter @type="REPORT" | fields greatest(@initDuration, 0) + @duration as duration, ispresent(@initDuration) as coldStart | stats count(*) as count, pct(duration, 50) as p50, pct(duration, 90) as p90, pct(duration, 99) as p99, max(duration) as max by coldStart 19
  • 20. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. CPU Architectures Two architecture options: • x86_64 • Arm64 (powered by graviton2) Why Arm64? Up to 19% better performance, and 20% lower cost. Things to keep in mind Binaries need to be compiled for Arm64. Some libraries/tools might not be optimized for Arm64 yet. 20
  • 21. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. Other notable features 21
  • 22. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Other notable features Lambda Function URL Create & configure dedicated HTTPS endpoint for your Lambda function. Amazon EFS Integration Mount an EFS file system to a local directory. Code Signing Ensure only trusted code runs in your Lambda functions. Up to 10GB Ephemeral Storage Configure /tmp storage between 512MB and 10GB. Amazon RDS Proxy Pool database connections to reach high concurrency without exhausting DB connections. 22
  • 23. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. Quotas & best practices 23
  • 24. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Important quotas • Concurrent executions: 1000, can be increased to hundreds of thousands • Burst capacity limit: 500-3000, hard limit • Invocation payload: 6MB sync, 256KB async • Deployment package: • Zip file: 50MB zipped, 250MB unzipped • Container image: 10GB • Temporary storage: 512MB – Free (can go up to 10GB with additional cost) • Invocations per second: • Sync/Async non-AWS: 10x concurrent execution quota • Async AWS: unlimited • Provisioned concurrency: 10x provisioned concurrency • ENIs per VPC: 100 24
  • 25. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. AWS Lambda Powertools • Tracing with AWS X-Ray For end-to-end observability • Structured logging for search and aggregation • Custom metrics with CloudWatch Logs EMF Python: https://github.com/awslabs/aws-lambda- powertools-python Java: https://github.com/awslabs/aws-lambda- powertools-java Typescript: https://github.com/awslabs/aws-lambda- powertools-typescript 25
  • 26. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Error handling Synchronous: The function returns an error to the caller. Asynchronous: Configure destination on the function to alert and store failures. Event Source Mapping (SQS): Setup a dead-letter queue (DLQ) on the queue. Event Source Mapping (other sources): Configure destination on the event source mapping to alert and store failures. 26
  • 27. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Function optimizations • Take advantage of EE reuse by initializing resources outside of the function handler. • Minimize the size of your deployment package to its runtime necessities. • Opt for dependencies that load quickly when possible. 27
  • 28. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Well-Architected Framework Serverless Lens: Well-architected questions and guidance for serverless workloads. https://docs.aws.amazon.com/ wellarchitected/latest/serverless-applications- lens/welcome.html Serverless Rules: Infrastructure-as-code linter to validate against best practices. E.g.: • Function with tracing disabled • Asynchronous function without failure destination https://github.com/aws- samples/serverless-rules
  • 29. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Serverless demos in various languages Go https://github.com/aws-samples/serverless-go- demo Groovy https://github.com/aws-samples/serverless- groovy-demo Java (GraalVM) https://github.com/aws-samples/serverless- graalvm-demo Kotlin https://github.com/aws-samples/serverless- kotlin-demo Micronaut/Quarkus/SpringBoot https://github.com/aws-samples/serverless- java-frameworks-samples .NET https://github.com/aws-samples/serverless- dotnet-demo Rust https://github.com/aws- samples/serverless-rust-demo Typescript https://github.com/aws- samples/serverless-typescript-demo 29
  • 30. AWS LAMBDA DEEP DIVE © 2022, Amazon Web Services, Inc. or its affiliates. Thank you! © 2022, Amazon Web Services, Inc. or its affiliates. 30 Dhiraj Mahapatro [email protected] Twitter: @dhirajmahapatro LinkedIn: dmahapatro