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!
Ad

More Related Content

What's hot (6)

2016 - Serverless Microservices on AWS with API Gateway and Lambda
2016 - Serverless Microservices on AWS with API Gateway and Lambda2016 - Serverless Microservices on AWS with API Gateway and Lambda
2016 - Serverless Microservices on AWS with API Gateway and Lambda
devopsdaysaustin
 
AWS Lambda
AWS LambdaAWS Lambda
AWS Lambda
Scott Leberknight
 
AWS Lambda
AWS LambdaAWS Lambda
AWS Lambda
Danilo Poccia
 
Simple Security for Startups
Simple Security for StartupsSimple Security for Startups
Simple Security for Startups
Mark Bate
 
Amazon API Gateway
Amazon API GatewayAmazon API Gateway
Amazon API Gateway
Mark Bate
 
amazon-cognito-auth-in-minutes
amazon-cognito-auth-in-minutesamazon-cognito-auth-in-minutes
amazon-cognito-auth-in-minutes
Vladimir Budilov
 
2016 - Serverless Microservices on AWS with API Gateway and Lambda
2016 - Serverless Microservices on AWS with API Gateway and Lambda2016 - Serverless Microservices on AWS with API Gateway and Lambda
2016 - Serverless Microservices on AWS with API Gateway and Lambda
devopsdaysaustin
 
Simple Security for Startups
Simple Security for StartupsSimple Security for Startups
Simple Security for Startups
Mark Bate
 
Amazon API Gateway
Amazon API GatewayAmazon API Gateway
Amazon API Gateway
Mark Bate
 
amazon-cognito-auth-in-minutes
amazon-cognito-auth-in-minutesamazon-cognito-auth-in-minutes
amazon-cognito-auth-in-minutes
Vladimir Budilov
 

Similar to Stephen Liedig: Building Serverless Backends with AWS Lambda and API Gateway (7)

Getting Started with AWS Lambda and Serverless Computing
Getting Started with AWS Lambda and Serverless ComputingGetting Started with AWS Lambda and Serverless Computing
Getting Started with AWS Lambda and Serverless Computing
Kristana Kane
 
2016-06 - Design your api management strategy - AWS - Microservices on AWS
2016-06 - Design your api management strategy - AWS - Microservices on AWS2016-06 - Design your api management strategy - AWS - Microservices on AWS
2016-06 - Design your api management strategy - AWS - Microservices on AWS
SmartWave
 
Building serverless app_using_aws_lambda_b4usolution
Building serverless app_using_aws_lambda_b4usolutionBuilding serverless app_using_aws_lambda_b4usolution
Building serverless app_using_aws_lambda_b4usolution
Hoa Le
 
Serverless Computing
Serverless Computing Serverless Computing
Serverless Computing
Rushi Namani
 
Getting Started with AWS Lambda & Serverless Cloud
Getting Started with AWS Lambda & Serverless CloudGetting Started with AWS Lambda & Serverless Cloud
Getting Started with AWS Lambda & Serverless Cloud
Ian Massingham
 
Serverless design considerations for Cloud Native workloads
Serverless design considerations for Cloud Native workloadsServerless design considerations for Cloud Native workloads
Serverless design considerations for Cloud Native workloads
Tensult
 
AWS Amplify
AWS AmplifyAWS Amplify
AWS Amplify
AWS Riyadh User Group
 
Getting Started with AWS Lambda and Serverless Computing
Getting Started with AWS Lambda and Serverless ComputingGetting Started with AWS Lambda and Serverless Computing
Getting Started with AWS Lambda and Serverless Computing
Kristana Kane
 
2016-06 - Design your api management strategy - AWS - Microservices on AWS
2016-06 - Design your api management strategy - AWS - Microservices on AWS2016-06 - Design your api management strategy - AWS - Microservices on AWS
2016-06 - Design your api management strategy - AWS - Microservices on AWS
SmartWave
 
Building serverless app_using_aws_lambda_b4usolution
Building serverless app_using_aws_lambda_b4usolutionBuilding serverless app_using_aws_lambda_b4usolution
Building serverless app_using_aws_lambda_b4usolution
Hoa Le
 
Serverless Computing
Serverless Computing Serverless Computing
Serverless Computing
Rushi Namani
 
Getting Started with AWS Lambda & Serverless Cloud
Getting Started with AWS Lambda & Serverless CloudGetting Started with AWS Lambda & Serverless Cloud
Getting Started with AWS Lambda & Serverless Cloud
Ian Massingham
 
Serverless design considerations for Cloud Native workloads
Serverless design considerations for Cloud Native workloadsServerless design considerations for Cloud Native workloads
Serverless design considerations for Cloud Native workloads
Tensult
 
Ad

Recently uploaded (20)

Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from AnywhereAutomation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Lynda Kane
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Datastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptxDatastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptx
kaleeswaric3
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Asthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdfAsthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdf
VanessaRaudez
 
Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.
gregtap1
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
"PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System""PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System"
Jainul Musani
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Buckeye Dreamin' 2023: De-fogging Debug Logs
Buckeye Dreamin' 2023: De-fogging Debug LogsBuckeye Dreamin' 2023: De-fogging Debug Logs
Buckeye Dreamin' 2023: De-fogging Debug Logs
Lynda Kane
 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Leading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael JidaelLeading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael Jidael
Michael Jidael
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from AnywhereAutomation Hour 1/28/2022: Capture User Feedback from Anywhere
Automation Hour 1/28/2022: Capture User Feedback from Anywhere
Lynda Kane
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Datastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptxDatastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptx
kaleeswaric3
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Asthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdfAsthma presentación en inglés abril 2025 pdf
Asthma presentación en inglés abril 2025 pdf
VanessaRaudez
 
Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.
gregtap1
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
"PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System""PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System"
Jainul Musani
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Buckeye Dreamin' 2023: De-fogging Debug Logs
Buckeye Dreamin' 2023: De-fogging Debug LogsBuckeye Dreamin' 2023: De-fogging Debug Logs
Buckeye Dreamin' 2023: De-fogging Debug Logs
Lynda Kane
 
Image processinglab image processing image processing
Image processinglab image processing  image processingImage processinglab image processing  image processing
Image processinglab image processing image processing
RaghadHany
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Leading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael JidaelLeading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael Jidael
Michael Jidael
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Ad

Stephen Liedig: Building Serverless Backends with AWS Lambda and API Gateway

  • 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)