Learning Objectives:
- Learn the basics of AWS Lambda and Amazon API Gateway
- Understand how to build a web application using these services
- Learn to architect a serverless application
- Gain an overview of frameworks for building serverless applications
What if you could build a web application that could support true web-scale traffic without having to ever provision or manage a single server? In this session, you will learn how to build a serverless website that scales automatically using services like AWS Lambda, Amazon API Gateway, and Amazon S3. We will review several frameworks that can help you build serverless applications, such as the AWS Serverless Application Model (AWS SAM), Chalice, and ClaudiaJS.
4. Benefits of Lambda
No servers to provision
or manage
Scales with usage
Never pay for idle Availability and fault
tolerance built in
5. Never pay for Idle
EVENT DRIVEN CONTINUOUS SCALING PAY BY USAGE
6. Function versioning and aliases
• Versions = immutable copies of
code + configuration
• Aliases = mutable pointers to
versions
• Each version/alias gets its own
ARN
• Enables rollbacks, staged
promotions, “locked” behavior for
client
Lambda Function
Version $LATEST
Lambda Function
Version 123
Lambda Function
DEV Alias
Lambda Function
BETA Alias
Lambda Function
PROD Alias
7. Lambda Environment Variables
• Key-value pairs
• Available via standard environment variable
access, such as process.env, or os.environ
• Can optionally be encrypted via AWS KMS
8. Common Lambda 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
10. Unify multiple microservices
under single API front-end
Authenticate and
Authorize Requests
Throttling and DDoS Protection
Amazon API Gateway
11. Amazon EC2 Instances
Lambda Functions
Other AWS Services
API Gateway
On Premise Servers
/v1/user /v1/user/image
Unified API
12. SIGv4 Lambda Custom Auth
{ }
API Keys
• Invoke with Caller Credentials
• AWS Identity and Access
Management (IAM) Roles
• Amazon Cognito
• Per Method Authorization
• OAuth
• On Premise Authentication
• Custom built auth
• Usage Plans
• Quotas per API Key
• Throttling per API Key
• Per Method Authorization
Auth
13. Throttling / DDoS / Scaling
DDoS Protection
• Layer 7 and Layer 3 Protection
• Cloudfront in front of API Gateway
Throttling
• Usage Plans
• Quotas per API Key
• Throttling per API Key
Scaling
• Auto Scaling
• Caching Layer
14. API Gateway Stage Variables
• Stage variables act like environment variables
• Use stage variables to store configuration values
• Stage variables are available in the $context object
• Values are accessible from most fields in API Gateway
• Lambda Function ARN
• HTTP endpoint
• Custom authorizer function name
• Parameter mappings
20. Monolithic - What does it look like?
GET /pets
PUT /pets
DELETE /pets
GET /describe/pet/$id
PUT /describe/pet/$id
EVENT DRIVEN ONE LARGE LAMBDA FUNCTION
21. Monolithic - Pros and Cons
• Single Handler
• Handles all GET/PUT/POST/UPDATE/DELETE
• Very Large Lambda Function
• Have to build a routing mechanism
• Larger blast radius
Cons:
Pros:
• Sometimes its easier to comprehend a less
distributed system
• Deployments “could” be faster
25. Microservices - What does it look like?
EVENT DRIVEN ONE LAMBDA PER HTTP METHOD
GET /pets
PUT /pets
DELETE /pets
GET /describe/pet/$id
PUT /describe/pet/$id
26. Microservices - Pros and Cons
• Can be harder to debug (X-ray can help with this!)
• Multiple Lambda Functions to Manage (Use SAM!!!!)
Cons:
Pros:
• Easier for teams to work Autonomously
• Separation of components
• Fine grained deployments (Integration testing is important)
• Can be easier to debug
• Agile
27. What does it look like put together?
Amazon
S3
Amazon
API Gateway
S3 stores all of your static
content: CSS, JS, Images, etc.
API Gateway handles all of
your application routing.
Lambda runs all of the logic
behind your website. Such as
a Create/Read/Update/Delete
service.
28. How do I manage it?
MEET SAM
USE SAM TO BUILD TEMPLATES THAT DEFINE
YOUR SERVERLESS APPLICATIONS
DEPLOY YOUR SAM TEMPLATE
WITH AWS CLOUDFORMATION
29. AWS Serverless Application Model (SAM)
AWS CloudFormation extension optimized
for serverless
New serverless resource types: functions,
APIs, and tables
Supports anything CloudFormation supports
Open specification (Apache 2.0)
33. ClaudiaJS
var ApiBuilder = require('claudia-api-builder')
var api = new ApiBuilder();
module.exports = api;
api.get('/hello', function () {
return 'hello world';
});
app.js
$ claudia create --region us-east-1 --api-module app
34. Chalice
from chalice import Chalice
app = Chalice(app_name="helloworld")
@app.route("/")
def index():
return {"hello": "world"}
app.py
$ deploy
Your chalice application is available at: https://endpoint/dev
35. Wrap-Up
Things to remember:
• AWS SAM (Serverless Application Model)
• Helps you define your entire Serverless application
• Lots of frameworks out there to help you get started
quickly
• ClaudiaJS, Zappa, Sparta, Apex, Chalice, aws-
serverless-express, Lambada, Serverless Framework
• If you’re just getting started, Start small!
• If you have questions, don’t be afraid to ask, the
community around Serverless is fantastic!