This document provides an overview of serverless computing on AWS and how to build and deploy serverless applications. It discusses what serverless computing is, common use cases, serverless patterns using AWS Lambda and Amazon API Gateway, examples of what customers are building, and how to do safe deployments of serverless apps using the AWS Serverless Application Model and AWS CodeDeploy.
2. About me
• Software Engineer & Web Developer
• Serverless Lover & AI Enthusiast
• AWS Customer since 2013
3. Agenda
1. What is serverless computing
2. Serverless patterns on AWS
3. What customers are building
4. Safe deployments for AWS Lambda
5. Demo time
bit.ly/cape-town-serverless
10. Using AWS Lambda
Simple resource model
• Select power rating
from 128 MB to 3 GB
• CPU and network
allocated
proportionately
Flexible use
• Synchronous or
asynchronous
• Integrated with other
AWS services
Flexible authorization
• Securely grant access to
resources and VPCs
• Fine-grained control for
invoking your functions
Bring your own code
• Node.js, Java, Python,
C#, Go
• Bring your own libraries
(even native ones)
11. Using AWS Lambda
Authoring functions
• WYSIWYG editor or
upload packaged .zip
• AWS Cloud9 IDE
• Third-party plugins
(Eclipse, Visual Studio)
Monitoring and logging
• Metrics for requests,
errors, and throttles
• Built-in logs to Amazon
CloudWatch Logs
• Distributed tracing with
AWS X-Ray
Programming model
• Use processes, threads,
/tmp, sockets normally
• AWS SDK built in
(Python and Node.js)
Stateless
• Persist data using
external storage
• No affinity or access to
underlying infrastructure
12. AWS Lambda Execution Model
Synchronous (push) Asynchronous (event) Stream-based
Amazon
API Gateway
AWS Lambda
function
Amazon
DynamoDBAmazon
SNS
AWS Lambda
function
Amazon
S3
reqs changes
AWS Lambda
service
function
/order
Amazon
Kinesis
13. Amazon API Gateway
Unified API
frontend
Authenticate and
authorize requests
DDoS protection
and throttling
Throttle, meter,
and monetize APIs
14. Mobile Apps
Websites
Services
Amazon API Gateway
API Gateway
Cache
Public
Endpoints on
Amazon EC2
Amazon
CloudWatch
Monitoring
All publicly
accessible
endpoints
Lambda
Functions
Endpoints
in VPC
Applications
& Services
in VPC
Any other
AWS service
Fully-managed
CloudFront
Distribution
Edge-OptimizedRegionalPrivate
Customer-managed
CloudFront
Distribution
Applications
& Services
in the same
AWS Region
AWS Direct
Connect
On-premises
Amazon API Gateway Integrations
15. AWS Lambda@Edge
Write Node.js code,
upload it to Lambda,
and run it on 120+
edge locations
Run code at an AWS
location close to your end
user with CloudFront’s
global network
Leverage computation at
the edge and CloudFront’s
caching functionalities to
reduce origin load
Programing modelReduce Origin LoadGlobal network
New
24. WHY WE CHOSE AWS (AND SERVERLESS)
Developers focus
on building
functionality
Multiple
programming
languages co-exist
Platform stability Scalability &
Availability
25. WHY WE CHOSE AWS (AND SERVERLESS)
Architectural &
release agility
AWS Free TierSafe & gradual
deployments
Deep visibility into
code execution &
performance
26. VITAL STATS
FIRST 6 MONTHS AFTER LAUNCH
• Mobile App Downloads
~ 60,000
• Lambda Invocations
~ 1,2 million monthly
• AWS Costs
$173 to $1,400 monthly (R2,400 to R20k)
Stable costs despite the linear growth
30. AWS Serverless Application Model (SAM)
Simplified template driven deployment
model for serverless applications
Supported serverless resource types:
functions, APIs, and tables
Supports anything AWS CloudFormation
supports
Open specification (Apache 2.0)
github.com/awslabs/serverless-application-model
31. SAM Template
Tells AWS CloudFormation this is a
SAM template it needs to transform
Creates a Lambda function with the
referenced managed IAM policy,
runtime, code at the referenced zip
location, and handler as defined.
Also creates an API Gateway and
takes care of all mapping and
permissions necessary
Creates a DynamoDB table with five
read & write units
AWSTemplateFormatVersion: '2010-09-09’
Transform: AWS::Serverless-2016-10-31
Resources:
GetHtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/todo_list.zip
Handler: index.gethtml
Runtime: nodejs4.3
Policies: AmazonDynamoDBReadOnlyAccess
Events:
GetHtml:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
ListTable:
Type: AWS::Serverless::SimpleTable
32. SAM Template Properties
Handler: index.js
Runtime: nodejs4.3
CodeUri: 's3://my-bucket/my-function.zip'
Description: Creates thumbnails
MemorySize: 1024
Timeout: 15
Policies: AmazonS3FullAccess
Environment:
Variables:
TABLE_NAME: my-table
Events:
PhotoUpload:
Type: S3
Properties:
Bucket: my-photo-bucket
Tracing: Active|PassThrough
From SAM version 2016-10-31
AWS::Serverless::Function
AWS::Serverless::Api
AWS::Serverless::SimpleTable
33. SAM Template Properties
StageName: prod
DefinitionUri: swagger.yml
CacheClusterEnabled: true
CacheClusterSize: 28.4
Variables:
VarName: VarValue
From SAM version 2016-10-31
AWS::Serverless::Function
AWS::Serverless::Api
AWS::Serverless::SimpleTable
34. SAM Template Properties
PrimaryKey:
Name: id
Type: String
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
From SAM version 2016-10-31
AWS::Serverless::Function
AWS::Serverless::Api
AWS::Serverless::SimpleTable
35. github.com/awslabs/aws-sam-local
AWS SAM CLI
CLI tool for local testing of serverless apps
Works with Lambda functions and “proxy-style” APIs
Response object and function logs available on your
local machine
Uses open-source Docker-Lambda images to mimic
Lambda’s execution environment (timeout, memory
limits, runtimes)