© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Welcome slide
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Unlocking serverless web
applications with AWS Lambda
Web Adapter
Harold Sun
BOA311
Senior Serverless Specialist SA
AWS
Betty Zheng
Senior Developer Advocate
AWS
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Agenda
Challenges of building serverless web applications
Inventing AWS Lambda Web Adapter
Migrating web apps to Lambda
Enhancing Lambda runtimes
Unlocking serverless web applications
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Challenges
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Running web applications on AWS Lambda
The programming model of Lambda functions is different from
traditional web applications
Migrating from traditional web applications to Lambda requires
additional work
Migrating from Lambda to containers usually requires code changes
The development and debugging tools are different
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Event source Services
Changes in
data state
Requests to
endpoints
Changes in
Resource state
Function
Node.js
Python
Java
C#
Go
Ruby
Runtime API
Lambda programming model
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Handler() function
Function to be executed
upon invocation
Event object
Data sent during Lambda
function invocation
Context object
Methods available to interact
with runtime information
(request ID, log group, etc.)
Lambda function handler
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Sample code for
an http Lambda
function
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
What about using a framework-specific adapter?
Using framework-specific adapters
help to deploy existing code as a
Lambda funcion
Drawbacks:
Need to add a new dependency
to the code
Long-term maitenance of the
adapter packages
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Migration and portability
Lift and shift
Portability
AWS Lambda
Amazon EKS
Amazon EC2
Amazon ECS
???
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Inventing Lambda Web Adapter
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
The inspirations
Serverlessish by Adian Steele
re:Web by apparentorder
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS Lambda Web Adapter
OPEN- S O U R C E T O O L T O R U N W E B A P P S O N A W S L A M B D A
Lambda-adapter
OS packages
Runtime
interface
client
Web
app
http-
adapter
Amazon API Gateway
endpoint
Lambda
function URLs
Application Load
Balancer
Lambda
function
invoke
Rest/HTTP API event
HTTP API v2 event*
ALB event
G
eneric
adapter for
Lambda
r
untime API and
HTTP API
No new code dependency
Support any web
frameworks
Support any programing
language
Develop and test locally
with existing tools
Supports both x86_64 and
arm64 CPU architectures
Both zip and OCI packaging
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS Lambda Web Adapter
OPEN- S O U R C E T O O L T O R U N W E B A P P S O N A W S L A M B D A
https://github.com/awslabs/aws-lambda-web-adapter
Lambda service API endpoints Processes
Lambda
Web
Adapter
Extension API
Runtime API
Execution environment
Web
application
http
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS Lambda Rust runtime
https://github.com/awslabs/aws-lambda-rust-runtime
The Lambda Web Adapter is implemented in Rust, utilizing crates such as AWS Lambda Rust
runtime and hyper. This choice not only ensures high performance but also enhances the safety
of this component within the latency-sensitive data path.
Rust logo by Rust Foundation / CC BY 4.0.
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Sequence diagram
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Example: Run an express.js app on Lambda
One line to install AWS Lambda Web Adapter
install Lambda Web Adapter
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
A question about performance
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
The result
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Migrating web apps to Lambda
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
A progressive way to adopt serverless
The Lambda-lith
The serverless microservices The single-purpose functions
API Gateway
Lambda function
Table
API Gateway
Product function Order function
Product
table
Order
table
/order/product
/{proxy+}
API Gateway
Product
table
Order
table
GET /order
/product
Product function
Get Order
function
New Order
function
POST /order
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Deploying imgproxy on AWS Lambda
Amazon CloudFront AWS Lambda
Amazon S3
FROM darthsim/imgproxy:latest
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.7.1
/lambda-adapter /opt/extensions/lambda-adapter
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Migrate Java web applications to Lambda
Quickly migrate a Spring Boot application to Lambda with Web Adapter
Application
Load
Balancer
Spring Boot
app
Auto Scaling group
Spring Boot
app
Spring Boot
app
Spring Boot on
Lambda with
Lambda SnapStart
Application
Load
Balancer
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS Lambda SnapStart
Download
cust. code
Start new
MicroVM
Initialize
cust. code
Snapshot
initialization
Take
snapshot
Run
handler
Warm
start
Resume
snapshot
Cold start
AWS
optimization
Customer
optimization
Function
create or
update
lifecycle
Request
lifecycle
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Demo
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Enhancing Lambda runtimes
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Lambda reponse streaming
Reduce TTFB
Faster response time
Larger payload
Up to 20MB (soft limit)
AWS Lambda response streaming is a new feature that allows Lambda functions
to send response data to clients as it becomes available. This feature can
improve performance for web and mobile applications.
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Response streaming for custom runtime
Custom runtimes can implement response streaming using the following response format to runtime API
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Next.js streaming with
suspense on Lambda
Hosting Next.js v13 app on AWS
Lambda Web Adapter
Streaming with suspense
Server-side rendering
Selective hydration
Much faster time to first byte
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Streaming response from Amazon Bedrock
AWS cloud
Mobile client
Lambda
function URL
Amazon Bedrock
Web Adapter supports response streaming on all AL2 runtimes, including Python runtime
request
request request
chunks
chunks
chunks
Lambda Web
Adapter
Web
application
request
chunks
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Demo
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Unlocking serverless web applications
with Lambda Web Adapter
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Running serverless web applications with
Lambda Web Adapter
Familiar programming
model and tools
Easy migration to
Lambda
Portability among
Lambda, AWS Fargate,
Amazon EC2
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Lambda Web Adapter
usage statics
Total downloads from
Amazon ECR public tripled
in 5 months
Served hundreds of millions
invokes every month
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
When people want to move their existing Django
applications to the cloud, I always recommend AWS
Lambda with Lambda Web Adapter. This allows them to
use familiar tools while benefiting from the scalability
and cost savings of running on AWS Lambda.
Efi Merdler-Kravitz
Head of Engineering, CloudEx
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Thanks to the Lambda Web Adapter, I have more
reasons than ever to make AWS Lambda my compute
platform of choice for containerized, full-stack, web
application frameworks such as Rails. I promise you,
this is going to be huge. Ive never been more happy to
delete custom integration code. Thanks AWS!
Ken Collins
Principal Engineer, CustomInk
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Resources
Lambda Web Adapter
GitHub repo
Using response streaming with
AWS Lambda Web Adapter to
optimize performance
Lifting and shifting a web
application to
AWS Serverless
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Check out these other sessions
BOA304 | Using AI and serverless to automate video production
Wynn | Upper Level | Cristal 7
Nov. 30 | 11:30 AM - 12:30 PM
BOA402 | Open source LLM optimization with Amazon SageMaker
Caesars Forum | Level 1 | Forum 123
Nov. 30 | 2:00 PM - 3:00 PM
SVS323 | I didn’t know Amazon API Gateway did that
Mandalay Bay | Level 1 | North | Islander G
Nov. 30 | 4:00 PM - 5:00 PM
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Thank you!
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Please complete the session
survey in the mobile app
Thank you
Harold Sun
@sunhua
Betty Zheng
@bettyzheng78