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