SlideShare ist ein Scribd-Unternehmen logo
1 von 64
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Chris Munns – Senior Developer Advocate – AWS
Serverless
Jan 23, 2018
Overview of Serverless
Application Deployment
Patterns
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
About me:
Chris Munns - munns@amazon.com, @chrismunns
• Senior Developer Advocate - Serverless
• New Yorker
• Previously:
• AWS Business Development Manager – DevOps, July ’15 - Feb ‘17
• AWS Solutions Architect Nov, 2011- Dec 2014
• Formerly on operations teams @Etsy and @Meetup
• Little time at a hedge fund, Xerox and a few other startups
• Rochester Institute of Technology: Applied Networking and Systems
Administration ’05
• Internet infrastructure geek
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
https://secure.flickr.com/photos/mgifford/4525333972
Why are we
here today?
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
No servers to provision
or manage
Scales with usage
Never pay for idle Availability and fault
tolerance built in
Serverless means…
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
SERVICES (ANYTHING)
Changes in
data state
Requests to
endpoints
Changes in
resource state
EVENT SOURCE FUNCTION
Node.js
Python
Java
C#
Go
Serverless applications
Lambda execution model
Synchronous
(push)
Asynchronous
(event)
Stream-based
Amazon
API Gateway
AWS Lambda
function
Amazon
DynamoDBAmazon
SNS
/order
AWS Lambda
function
Amazon
S3
reqs
Amazon
Kinesis
changes
AWS Lambda
service
function
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon API Gateway
Internet
Mobile Apps
Websites
Services
AWS Lambda
functions
AWS
API Gateway
Cache
Endpoints on
Amazon EC2
All publicly and
privately accessible
endpoints
Amazon
CloudWatch
Monitoring
Amazon
CloudFront
Any other
AWS service
Regional API Endpoints
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
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
IT
Automation
• Policy engines
• Extending
AWS services
• Infrastructure
management
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Serverless
Deployment
Patterns
https://www.flickr.com/photos/volvob12b/15012162252/
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
version NEW
How do we deploy a new version of our code?
version OLD
?
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Serverless Deployment Pattern Considerations
Minimizing Impact
to consumers
Rollback technique Execution model
factors
Deployment Speed
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Serverless Deployment Patterns
All at once
All traffic goes from
version OLD to
NEW at once.
Canaries/Linear
A small % of
production traffic is
sent to version NEW,
the remainder to
version OLD. After
some period of
waiting for validation,
traffic is shifted
incrementally (with
further validation) or
fully to version NEW.
Blue/Green
Version NEW is
deployed and
tested against
before taking
production traffic.
After validated all
traffic goes from
version OLD to
NEW at once.
Serverless Deployment Patterns Consideration Matrix
Consumer impact Rollback Event Model
Factors
Deployment
Speed
All at once All at once Redeploy
older version
Any event model
at low concurrency
rate
Immediate
Blue/Green All at once with some
level of production
environment testing
beforehand
Revert traffic
to OLD
Better for async
and sync event
models at medium
concurrency
workloads
Minutes to
hours of
validation and
then immediate
to customers
Canaries/
Linear
1-10% typical initial
traffic shift, then
phased increases or
all at once
Revert traffic
to OLD
Better for high
concurrency
workloads
Minutes to
hours
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Tools for Serverless
Application
Deployment
https://secure.flickr.com/photos/lox/9408028555
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Meet
SAM!
AWS Serverless Application Model (SAM)
CloudFormation extension optimized for
serverless
New serverless resource types: functions, APIs,
and tables
Supports anything CloudFormation supports
Open specification (Apache 2.0)
https://github.com/awslabs/serverless-application-model
SAM template
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
SAM template
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
Tells 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/permissions necessary
Creates a DynamoDB table with 5
Read & Write units
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
From: https://github.com/awslabs/aws-serverless-samfarm/blob/master/api/saml.yaml
<-THIS
BECOMES THIS->
SAM template
SAM Template Properties
AWS::Serverless::Function
AWS::Serverless::Api
AWS::Serverless::SimpleTable
Handler: index.js
Runtime: nodejs4.3
CodeUri: 's3://my-code-bucket/my-function.zip'
Description: Creates thumbnails of uploaded
images
MemorySize: 1024
Timeout: 15
Policies: AmazonS3FullAccess
Environment:
Variables:
TABLE_NAME: my-table
Events:
PhotoUpload:
Type: S3
Properties:
Bucket: my-photo-bucket
Tracing: Active|PassThrough
Tags:
AppNameTag: ThumbnailApp
DepartmentNameTag: ThumbnailDepartmentFrom SAM Version 2016-10-31
AWS::Serverless::Function Event source types
From SAM Version 2016-10-31
S3
SNS
Kinesis | DynamoDB
Api
Schedule
CloudWatchEvent
IoTRule
AlexaSkill
Note: Events are a map of string to Event Source
Object
Event Source Objects have the following structure:
Type:
Properties:
For Example:
Events:
MyEventName:
Type: S3
Properties:
Bucket: my-photo-bucket
SAM commands – Package & Deploy
Package
•Creates a deployment package (.zip file)
•Uploads deployment package to an Amazon S3
Bucket
•Adds a CodeUri property with S3 URI
Deploy
•Calls CloudFormation ‘CreateChangeSet’ API
•Calls CloudFormation ‘ExecuteChangeSet’ API
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS SAM Local
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:
• Emulates timeout, memory limits,
runtimes
https://github.com/awslabs/aws-sam-local
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Deploying your
applications
https://secure.flickr.com/photos/simononly/15386966677
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Stage Variables and Lambda Aliases
Using Stage Variables in API Gateway together with Lambda function Aliases
you can manage a single API configuration and Lambda function for multiple
environment stages
myLambdaFunction
1
2
3 = prod
4
5
6 = beta
7
8 = dev
My First API
Stage variable = lambdaAlias
Prod
lambdaAlias = prod
Beta
lambdaAlias = beta
Dev
lambdaAlias = dev
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Alias Traffic Shifting & Safe Deployments
“By default, an alias points to a single Lambda function version. When the alias is
updated to point to a different function version, incoming request traffic in turn instantly
points to the updated version.”
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Alias Traffic Shifting & Safe Deployments
“By default, an alias points to a single Lambda function version. When the alias is
updated to point to a different function version, incoming request traffic in turn instantly
points to the updated version.
This exposes that alias to any potential instabilities introduced by the new version.”
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Alias Traffic Shifting & Safe Deployments
“By default, an alias points to a single Lambda function version. When the alias is
updated to point to a different function version, incoming request traffic in turn instantly
points to the updated version.
This exposes that alias to any potential instabilities introduced by the new version.
To minimize this impact, you can implement the routing-config parameter of the Lambda
alias that allows you to point to two different versions of the Lambda function and dictate
what percentage of incoming traffic is sent to each version.”
– AWS Lambda docs on “Traffic Shifting Using Aliases”
aws lambda update-alias --name alias name --function-name function-
name --routing-config AdditionalVersionWeights={”6"=0.05}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Alias Traffic Shifting
myLambdaFunction
1
2
3 = prod
4
5
6 = prod 5%
My First API
Stage variable = lambdaAlias
Prod
lambdaAlias = prod
aws lambda update-alias --name prod --function-name myLambdaFunction
--routing-config AdditionalVersionWeights={”6"=0.05}
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Alias Traffic Shifting
myLambdaFunction
5
6 = prod
My First API
Stage variable = lambdaAlias
Prod
lambdaAlias = prod
aws lambda update-alias --name prod --function-name myLambdaFunction
--function-version 6 --routing-config ''
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Alias Traffic Shifting & AWS Step Functions
Blog link: http://amzn.to/2FjlWA7
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
SAM Globals + Safe Deployments
Globals:
Function:
Runtime: nodejs4.3
AutoPublishAlias: !Ref ENVIRONMENT
MyLambdaFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
DeploymentPreference:
Type: Linear10PercentEvery10Minutes
Alarms:
# A list of alarms that you want to monitor
- !Ref AliasErrorMetricGreaterThanZeroAlarm
- !Ref LatestVersionErrorMetricGreaterThanZeroAlarm
Hooks:
# Validation Lambda functions that are run before & after traffic shifting
PreTraffic: !Ref PreTrafficLambdaFunction
PostTraffic: !Ref PostTrafficLambdaFunction
NEW!
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
SAM Globals + Safe Deployments
Globals:
Function:
Runtime: nodejs4.3
AutoPublishAlias: !Ref ENVIRONMENT
MyLambdaFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
DeploymentPreference:
Type: Linear10PercentEvery10Minutes
Alarms:
# A list of alarms that you want to monitor
- !Ref AliasErrorMetricGreaterThanZeroAlarm
- !Ref LatestVersionErrorMetricGreaterThanZeroAlarm
Hooks:
# Validation Lambda functions that are run before & after traffic shifting
PreTraffic: !Ref PreTrafficLambdaFunction
PostTraffic: !Ref PostTrafficLambdaFunction
NEW!
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Alias Traffic Shifting & AWS SAM
AutoPublishAlias
By adding this property and specifying an
alias name, AWS SAM will do the
following:
• Detect when new code is being
deployed based on changes to the
Lambda function's Amazon S3 URI.
• Create and publish an updated version
of that function with the latest code.
• Create an alias with a name you
provide (unless an alias already exists)
and points to the updated version of
the Lambda function.
Deployment Preference Type
Canary10Percent30Minutes
Canary10Percent5Minutes
Canary10Percent10Minutes
Canary10Percent15Minutes
Linear10PercentEvery10Minutes
Linear10PercentEvery1Minute
Linear10PercentEvery2Minutes
Linear10PercentEvery3Minutes
AllAtOnce
In SAM:
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda Alias Traffic Shifting & AWS SAM
Alarms: # A list of alarms that you want to monitor
- !Ref AliasErrorMetricGreaterThanZeroAlarm
- !Ref LatestVersionErrorMetricGreaterThanZeroAlarm
Hooks: # Validation Lambda functions that are run
before & after traffic shifting
PreTraffic: !Ref PreTrafficLambdaFunction
PostTraffic: !Ref PostTrafficLambdaFunction
In SAM:
Note: You can specify a maximum of 10 alarms
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
NEW: Can deploy AWS Lambda!!
Uses AWS SAM to deploy serverless applications
Supports Lambda Alias Traffic Shifting enabling
canaries and blue|green deployments
Can rollback based on CloudWatch Metrics/Alarms
Pre/Post-Traffic Triggers can integrate with other
services (or even call Lambda functions)
AWS CodeDeploy + Lambda
NEW!
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
CodeDeploy comes with a number of added
capabilities:
• Custom deployment configurations.
Examples:
• “Canary 5% for 1 hour”
• “Linear 20% every 1 hour”
• Notification events via SNS on
success/failure/rollback
• Console with visibility on deploy status,
history, and rollbacks.
AWS CodeDeploy + Lambda
NEW!
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon API Gateway Canary Support
Use canary release deployments to gradually roll out new APIs
in Amazon API Gateway:
• configure percent of traffic to go to a new stage deployment
• can test stage settings and variables
• API gateway will create additional Amazon CloudWatch Logs
group and CloudWatch metrics for the requests handled by
the canary deployment API
• To rollback: delete the deployment or set percent of traffic to 0
NEW!
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon API Gateway Canary Support
v1API
Clients
All publicly and
privately
accessible
endpoints
Backends
in AWS
api.mydomain.com/prod
All traffic to currently deployed version
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon API Gateway Canary Support
API
Clients
All publicly and
privately
accessible
endpoints
Backends
in AWS
v1
50%
v2
50%
api.mydomain.com/prod
50% traffic to new deployment of stage, rest to previous version
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon API Gateway Canary Support
API
Clients
All publicly and
privately
accessible
endpoints
Backends
in AWS
v1
90%
v2
10%
api.mydomain.com/prod
10% traffic to new deployment of stage, rest to previous version
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon API Gateway Canary Support
API
Clients
All publicly and
privately
accessible
endpoints
Backends
in AWS
v1
90%
v2
10%
api.mydomain.com/prod
10% traffic to new deployment of stage, rest to previous version
No changes to client
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon API Gateway Canary Support
v2API
Clients
All publicly and
privately
accessible
endpoints
Backends
in AWS
api.mydomain.com/prod
All traffic to new deployed version
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon API Gateway Canary Support
Interesting use-cases
• Explore new technologies in your API backend:
• New languages
• New frameworks
• Try Lambda in place of other HTTP endpoints!
• Compare/contrast performance with individual logs and
metrics
• Migrate an API from on-premises to AWS via endpoint
integrations in VPC (new)
• API-GW -> Network Load Balancer (NLB) -> on-prem
over Direct Connect or VPN connection
• Can test method by method or even action by action, no need
for an all at once move!
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda
• Single function is only
granularity
• Transparent to invoking
services
• Rollback by setting weight to 0
• Supports automating
increments changes via SAM
• new version has unique logs &
metrics
Comparing Lambda vs. API Gateway Canaries
API Gateway
• Entire stage is maximum
granularity
• Transparent to clients
• Rollback by setting weight to
zero or deleting canary
• Currently no native automated
tooling
• new version has unique logs &
metrics
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda
• Single function is only
granularity
• Transparent to invoking
services
• Rollback by setting weight to 0
• Supports automating
increments changes via SAM
• new version has unique logs &
metrics
Comparing Lambda vs. API Gateway Canaries
API Gateway
• Entire stage is maximum
granularity
• Transparent to clients
• Rollback by setting weight to
zero or deleting canary
• Currently no native automated
tooling
• new version has unique logs &
metrics
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
CloudWatch Metrics
• 7 Built in metrics for Lambda
• Can call “put-metric-data”
from your function code for
custom metrics
• New: Function
Concurrency
• 7 Built in metrics for API-
Gateway
Metrics and logging are a universal right!
CloudWatch Logs
• Lambda Logging
• Custom logging from your
code with your language’s
equivalent of console.log()
• API Gateway Logging
• New: Custom formats
• Log Pivots
• Build metrics based on log
filters
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Type: "AWS::CloudWatch::Alarm”
Properties:
ActionsEnabled: True
AlarmActions:
- "arn:aws:sns:us-east-1:1234567890abc:MunnsDemoALERT"
AlarmDescription: “Error if 5 errors in a single datapoint”
AlarmName: "SAM Lambda Error Alarm"
ComparisonOperator: "GreaterThanOrEqualToThreshold"
Dimensions:
-
Name: FunctionName
Value: ”my-function”
-
Name: Resource
Value: ”my-function"
EvaluationPeriods: 1
MetricName: "Errors"
Namespace: "AWS/Lambda"
Period: 300
Statistic: “Average”
Threshold: 5.0
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Building your
pipeline
https://www.flickr.com/photos/seattlemunicipalarchives/12504672623/
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Continuous delivery service for fast and
reliable application updates
Model and visualize your software release
process
Builds, tests, and deploys your code every time
there is a code change
Integrates with third-party tools and AWS
AWS CodePipeline
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
An example minimal Developer’s pipeline:
MyBranch-Source
Source
CodeCommit
MyApplication
Build
test-build-source
CodeBuild
MyDev-Deploy
create-changeset
AWS CloudFormation
execute-changeset
AWS CloudFormation
Run-stubs
AWS Lambda
This pipeline:
• Three Stages
• Builds code artifact
• One Development environment
• Uses SAM/CloudFormation to
deploy artifact and other AWS
resources
• Has Lambda custom actions for
running my own testing functions
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
An example minimal production pipeline:
This pipeline:
• Five Stages
• Builds code artifact
• Three deployed to “Environments”
• Uses SAM/CloudFormation to
deploy artifact and other AWS
resources
• Has Lambda custom actions for
running my own testing functions
• Integrates with a 3rd party
tool/service
• Has a manual approval before
deploying to production
Source
Source
CodeCommit
MyApplication
Build
test-build-source
CodeBuild
Deploy Testing
create-changeset
AWS
CloudFormation
execute-changeset
AWS
CloudFormation
Run-stubs
AWS Lambda
Deploy Staging
create-changeset
AWS
CloudFormation
execute-changeset
AWS
CloudFormation
Run-API-test
Runscope
QA-Sign-off
Manual Approval
Review
Deploy Prod
create-changeset
AWS
CloudFormation
execute-changeset
AWS
CloudFormation
Post-Deploy-Slack
AWS Lambda
Serverless Deployment Patterns Consideration Matrix
Consumer impact Rollback Event Model
Factors
Deployment
Speed
All at once All at once Redeploy
older version
Any event model
at low concurrency
rate
Immediate
Blue/Green All at once with some
level of production
environment testing
beforehand
Revert traffic
to OLD
Better for async
and sync event
models at medium
concurrency
workloads
Minutes to
hours of
validation and
then immediate
to customers
Canaries/
Linear
1-10% typical initial
traffic shift, then
phased increases or
all at once
Revert traffic
to OLD
Better for high
concurrency
workloads
Minutes to
hours
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Where and what to test?
Source
MyApplication
Build
Deploy Testing
Deploy Staging
Deploy Prod
• Code review via Pull
Requests
• (NEW In CodeCommit)
• Lint/syntax check
• Unit tests pass
• Code successfully
compiles
• All at once deploy
• Mocked/stubbed
integration tests
• All at once deploy
• Tests against real
dependencies (potentially
against production ones)
• Deploy new version and
direct all requests to it
1.
2.
3.
4.
5.
All at once model
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Where and what to test?
Source
MyApplication
Build
Deploy Testing
Deploy Staging
Deploy Prod
• Code review via Pull
Requests
• (NEW In CodeCommit)
• Lint/syntax check
• Unit tests pass
• Code successfully
compiles
• All at once deploy
• Mocked/stubbed
integration tests
• All at once deploy
• Tests against
dependencies
• Deploy green version
• Run tests against green
& validate
• Direct 100% to green
1.
2.
3.
4.
5.
Blue/Green model
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Where and what to test?
Source
MyApplication
Build
Deploy Testing
Deploy Staging
Deploy Prod
• Code review via Pull
Requests
• (NEW In CodeCommit)
• Lint/syntax check
• Unit tests pass
• Code successfully
compiles
• All at once deploy
• Mocked/stubbed
integration tests
• All at once deploy
• Tests against
dependencies
• Deploy canaries
• Complete wait period
successfully
• Deploy 100%
1.
2.
3.
4.
5.
Canary model
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Environments, Stages, Versioning, & Canaries?
A few best practices:
1. Use blue|green or canaries for production deployments with a
rollback as automated as possible
2. In Lambda Versioning is useful if you need to support multiple
versions to multiple consumers/invocation points
3. In API-Gateway Stages work similarly and are useful if you need to
support multiple API versions
4. Try to always have separate “stacks” for Development, Testing,
Staging, Production environments
1. Do not use Stages or Versioning for this
2. Think about having different accounts all together for different
environments
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
FIN, ACK
With the recent feature releases you can easily deploy Lambda functions in a
safe and controlled manner!
Some key takeaways:
• automatic rollbacks should be your first line of recovery for deployment
related issues
• different event models and different workload sizes can cause you to use
different deployment patterns
• decide on the most key metric to rollback or fail a deployment on related to
how a bad deployment might impact your customers
• AWS SAM + AWS CodeDeploy enable you to easily do all at once,
blue|green, and canary based deployments for serverless applications!
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
aws.amazon.com/serverless
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Chris Munns
munns@amazon.com
@chrismunnshttps://www.flickr.com/photos/theredproject/3302110152/
© 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
?
https://secure.flickr.com/photos/dullhunk/202872717/

Weitere ähnliche Inhalte

Was ist angesagt?

Building Global Serverless Backends powered by Amazon DynamoDB Global Tables
Building Global Serverless Backends powered by Amazon DynamoDB Global TablesBuilding Global Serverless Backends powered by Amazon DynamoDB Global Tables
Building Global Serverless Backends powered by Amazon DynamoDB Global Tables
Amazon Web Services
 

Was ist angesagt? (20)

AWS ECS Workshop A Journey to Modern Applications
AWS ECS Workshop A Journey to Modern ApplicationsAWS ECS Workshop A Journey to Modern Applications
AWS ECS Workshop A Journey to Modern Applications
 
Serverless - State of the Union
Serverless - State of the UnionServerless - State of the Union
Serverless - State of the Union
 
Deep Dive on Serverless Application Development
Deep Dive on Serverless Application DevelopmentDeep Dive on Serverless Application Development
Deep Dive on Serverless Application Development
 
Build and Deploy Serverless Applications with AWS SAM
Build and Deploy Serverless Applications with AWS SAM Build and Deploy Serverless Applications with AWS SAM
Build and Deploy Serverless Applications with AWS SAM
 
Serverless Applications with AWS SAM
Serverless Applications with AWS SAMServerless Applications with AWS SAM
Serverless Applications with AWS SAM
 
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
Gluecon 2018 - The Best Practices and Hard Lessons Learned of Serverless Appl...
 
Building Global Serverless Backends powered by Amazon DynamoDB Global Tables
Building Global Serverless Backends powered by Amazon DynamoDB Global TablesBuilding Global Serverless Backends powered by Amazon DynamoDB Global Tables
Building Global Serverless Backends powered by Amazon DynamoDB Global Tables
 
AWS Startup Day - Boston 2018 - The Best Practices and Hard Lessons Learned o...
AWS Startup Day - Boston 2018 - The Best Practices and Hard Lessons Learned o...AWS Startup Day - Boston 2018 - The Best Practices and Hard Lessons Learned o...
AWS Startup Day - Boston 2018 - The Best Practices and Hard Lessons Learned o...
 
re:Invent Deep Dive on Lambda Layers and Runtime API
re:Invent Deep Dive on Lambda Layers and Runtime APIre:Invent Deep Dive on Lambda Layers and Runtime API
re:Invent Deep Dive on Lambda Layers and Runtime API
 
Advanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step FunctionsAdvanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step Functions
 
Deep Dive on Serverless Application Development
Deep Dive on Serverless Application DevelopmentDeep Dive on Serverless Application Development
Deep Dive on Serverless Application Development
 
Containers State of the Union I AWS Dev Day 2018
Containers State of the Union I AWS Dev Day 2018Containers State of the Union I AWS Dev Day 2018
Containers State of the Union I AWS Dev Day 2018
 
Networking Best Practices for Your Serverless Applications
Networking Best Practices for Your Serverless ApplicationsNetworking Best Practices for Your Serverless Applications
Networking Best Practices for Your Serverless Applications
 
Deep Dive on Amazon Elastic Container Service (ECS) I AWS Dev Day 2018
Deep Dive on Amazon Elastic Container Service (ECS) I AWS Dev Day 2018Deep Dive on Amazon Elastic Container Service (ECS) I AWS Dev Day 2018
Deep Dive on Amazon Elastic Container Service (ECS) I AWS Dev Day 2018
 
Serverless Development Deep Dive
Serverless Development Deep DiveServerless Development Deep Dive
Serverless Development Deep Dive
 
Architecting ASP.NET Core Microservices Applications on AWS (WIN401) - AWS re...
Architecting ASP.NET Core Microservices Applications on AWS (WIN401) - AWS re...Architecting ASP.NET Core Microservices Applications on AWS (WIN401) - AWS re...
Architecting ASP.NET Core Microservices Applications on AWS (WIN401) - AWS re...
 
Introducing AWS Fargate
Introducing AWS FargateIntroducing AWS Fargate
Introducing AWS Fargate
 
Serverless and DevOps
Serverless and DevOpsServerless and DevOps
Serverless and DevOps
 
Getting Started with AWS Lambda and Serverless
Getting Started with AWS Lambda and ServerlessGetting Started with AWS Lambda and Serverless
Getting Started with AWS Lambda and Serverless
 
Building Global Multi-Region, Active-Active Serverless Backends I AWS Dev Day...
Building Global Multi-Region, Active-Active Serverless Backends I AWS Dev Day...Building Global Multi-Region, Active-Active Serverless Backends I AWS Dev Day...
Building Global Multi-Region, Active-Active Serverless Backends I AWS Dev Day...
 

Ähnlich wie Overview of Serverless Application Deployment Patterns - AWS Online Tech Talks

Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...
Amazon Web Services
 
How to Build Scalable Serverless Applications
How to Build Scalable Serverless ApplicationsHow to Build Scalable Serverless Applications
How to Build Scalable Serverless Applications
Amazon Web Services
 

Ähnlich wie Overview of Serverless Application Deployment Patterns - AWS Online Tech Talks (20)

Deep Dive On Serverless Application Development
Deep Dive On Serverless Application DevelopmentDeep Dive On Serverless Application Development
Deep Dive On Serverless Application Development
 
Deep Dive on Serverless Application Development
Deep Dive on Serverless Application DevelopmentDeep Dive on Serverless Application Development
Deep Dive on Serverless Application Development
 
Deep Dive on Serverless Application Development - Zlatan Dzinic
Deep Dive on Serverless Application Development - Zlatan DzinicDeep Dive on Serverless Application Development - Zlatan Dzinic
Deep Dive on Serverless Application Development - Zlatan Dzinic
 
Unlocking Agility with the AWS Serverless Application Model (SAM)
Unlocking Agility with the AWS Serverless Application Model (SAM)Unlocking Agility with the AWS Serverless Application Model (SAM)
Unlocking Agility with the AWS Serverless Application Model (SAM)
 
Serverless computing - Build and run applications without thinking about servers
Serverless computing - Build and run applications without thinking about serversServerless computing - Build and run applications without thinking about servers
Serverless computing - Build and run applications without thinking about servers
 
Serverless-AWS SAM CLI Session: Developer Meet Up
Serverless-AWS SAM CLI Session: Developer Meet UpServerless-AWS SAM CLI Session: Developer Meet Up
Serverless-AWS SAM CLI Session: Developer Meet Up
 
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...
 
使用 AWS 無伺服器化應用程式模型 (SAM) 釋放您的 "敏捷" 能量 (Level 300)
使用 AWS 無伺服器化應用程式模型 (SAM) 釋放您的 "敏捷" 能量 (Level 300)使用 AWS 無伺服器化應用程式模型 (SAM) 釋放您的 "敏捷" 能量 (Level 300)
使用 AWS 無伺服器化應用程式模型 (SAM) 釋放您的 "敏捷" 能量 (Level 300)
 
Forza Computazionale e Applicazioni Serverless
Forza Computazionale e Applicazioni ServerlessForza Computazionale e Applicazioni Serverless
Forza Computazionale e Applicazioni Serverless
 
Devops on serverless
Devops on serverlessDevops on serverless
Devops on serverless
 
All the Ops you need to know to Dev Serverless
All the Ops you need to know to Dev ServerlessAll the Ops you need to know to Dev Serverless
All the Ops you need to know to Dev Serverless
 
How to Build Scalable Serverless Applications
How to Build Scalable Serverless ApplicationsHow to Build Scalable Serverless Applications
How to Build Scalable Serverless Applications
 
Unlocking Agility with the AWS Serverless Application Model (SAM) - AWS Summi...
Unlocking Agility with the AWS Serverless Application Model (SAM) - AWS Summi...Unlocking Agility with the AWS Serverless Application Model (SAM) - AWS Summi...
Unlocking Agility with the AWS Serverless Application Model (SAM) - AWS Summi...
 
The Future of Enterprise Applications is Serverless (ENT314-R1) - AWS re:Inve...
The Future of Enterprise Applications is Serverless (ENT314-R1) - AWS re:Inve...The Future of Enterprise Applications is Serverless (ENT314-R1) - AWS re:Inve...
The Future of Enterprise Applications is Serverless (ENT314-R1) - AWS re:Inve...
 
Getting Started with AWS Lambda & Serverless Computing
Getting Started with AWS Lambda & Serverless ComputingGetting Started with AWS Lambda & Serverless Computing
Getting Started with AWS Lambda & Serverless Computing
 
What's New in Serverless - SRV305 - re:Invent 2017
What's New in Serverless - SRV305 - re:Invent 2017What's New in Serverless - SRV305 - re:Invent 2017
What's New in Serverless - SRV305 - re:Invent 2017
 
Build Modern Applications that Align with Twelve-Factor Methods (API303) - AW...
Build Modern Applications that Align with Twelve-Factor Methods (API303) - AW...Build Modern Applications that Align with Twelve-Factor Methods (API303) - AW...
Build Modern Applications that Align with Twelve-Factor Methods (API303) - AW...
 
Serverless Application Debugging and Delivery Best Practices (DEV307-R1) - AW...
Serverless Application Debugging and Delivery Best Practices (DEV307-R1) - AW...Serverless Application Debugging and Delivery Best Practices (DEV307-R1) - AW...
Serverless Application Debugging and Delivery Best Practices (DEV307-R1) - AW...
 
Ci/CD for AWS Lambda Projects - JLM CTO Club
Ci/CD for AWS Lambda Projects - JLM CTO ClubCi/CD for AWS Lambda Projects - JLM CTO Club
Ci/CD for AWS Lambda Projects - JLM CTO Club
 
Coordinating Microservices with AWS Step Functions.pdf
Coordinating Microservices with AWS Step Functions.pdfCoordinating Microservices with AWS Step Functions.pdf
Coordinating Microservices with AWS Step Functions.pdf
 

Mehr von Amazon Web Services

Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
Amazon Web Services
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
Amazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
Amazon Web Services
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
Amazon Web Services
 

Mehr von Amazon Web Services (20)

Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
 
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
 
Esegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateEsegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS Fargate
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWS
 
Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot
 
Open banking as a service
Open banking as a serviceOpen banking as a service
Open banking as a service
 
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
 
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
 
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsMicrosoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
 
Computer Vision con AWS
Computer Vision con AWSComputer Vision con AWS
Computer Vision con AWS
 
Database Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareDatabase Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatare
 
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSCrea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e web
 
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareDatabase Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
 
Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
 
Fundraising Essentials
Fundraising EssentialsFundraising Essentials
Fundraising Essentials
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container Service
 

Overview of Serverless Application Deployment Patterns - AWS Online Tech Talks

  • 1. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Chris Munns – Senior Developer Advocate – AWS Serverless Jan 23, 2018 Overview of Serverless Application Deployment Patterns
  • 2. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. About me: Chris Munns - munns@amazon.com, @chrismunns • Senior Developer Advocate - Serverless • New Yorker • Previously: • AWS Business Development Manager – DevOps, July ’15 - Feb ‘17 • AWS Solutions Architect Nov, 2011- Dec 2014 • Formerly on operations teams @Etsy and @Meetup • Little time at a hedge fund, Xerox and a few other startups • Rochester Institute of Technology: Applied Networking and Systems Administration ’05 • Internet infrastructure geek
  • 3. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. https://secure.flickr.com/photos/mgifford/4525333972 Why are we here today?
  • 4. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. No servers to provision or manage Scales with usage Never pay for idle Availability and fault tolerance built in Serverless means…
  • 5. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. SERVICES (ANYTHING) Changes in data state Requests to endpoints Changes in resource state EVENT SOURCE FUNCTION Node.js Python Java C# Go Serverless applications
  • 6. Lambda execution model Synchronous (push) Asynchronous (event) Stream-based Amazon API Gateway AWS Lambda function Amazon DynamoDBAmazon SNS /order AWS Lambda function Amazon S3 reqs Amazon Kinesis changes AWS Lambda service function
  • 7. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon API Gateway Internet Mobile Apps Websites Services AWS Lambda functions AWS API Gateway Cache Endpoints on Amazon EC2 All publicly and privately accessible endpoints Amazon CloudWatch Monitoring Amazon CloudFront Any other AWS service Regional API Endpoints
  • 8. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 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 IT Automation • Policy engines • Extending AWS services • Infrastructure management
  • 9. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Serverless Deployment Patterns https://www.flickr.com/photos/volvob12b/15012162252/
  • 10. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. version NEW How do we deploy a new version of our code? version OLD ?
  • 11. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Serverless Deployment Pattern Considerations Minimizing Impact to consumers Rollback technique Execution model factors Deployment Speed
  • 12. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Serverless Deployment Patterns All at once All traffic goes from version OLD to NEW at once. Canaries/Linear A small % of production traffic is sent to version NEW, the remainder to version OLD. After some period of waiting for validation, traffic is shifted incrementally (with further validation) or fully to version NEW. Blue/Green Version NEW is deployed and tested against before taking production traffic. After validated all traffic goes from version OLD to NEW at once.
  • 13. Serverless Deployment Patterns Consideration Matrix Consumer impact Rollback Event Model Factors Deployment Speed All at once All at once Redeploy older version Any event model at low concurrency rate Immediate Blue/Green All at once with some level of production environment testing beforehand Revert traffic to OLD Better for async and sync event models at medium concurrency workloads Minutes to hours of validation and then immediate to customers Canaries/ Linear 1-10% typical initial traffic shift, then phased increases or all at once Revert traffic to OLD Better for high concurrency workloads Minutes to hours
  • 14. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Tools for Serverless Application Deployment https://secure.flickr.com/photos/lox/9408028555
  • 15. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Meet SAM!
  • 16. AWS Serverless Application Model (SAM) CloudFormation extension optimized for serverless New serverless resource types: functions, APIs, and tables Supports anything CloudFormation supports Open specification (Apache 2.0) https://github.com/awslabs/serverless-application-model
  • 17. SAM template 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
  • 18. SAM template 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 Tells 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/permissions necessary Creates a DynamoDB table with 5 Read & Write units
  • 19. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. From: https://github.com/awslabs/aws-serverless-samfarm/blob/master/api/saml.yaml <-THIS BECOMES THIS-> SAM template
  • 20. SAM Template Properties AWS::Serverless::Function AWS::Serverless::Api AWS::Serverless::SimpleTable Handler: index.js Runtime: nodejs4.3 CodeUri: 's3://my-code-bucket/my-function.zip' Description: Creates thumbnails of uploaded images MemorySize: 1024 Timeout: 15 Policies: AmazonS3FullAccess Environment: Variables: TABLE_NAME: my-table Events: PhotoUpload: Type: S3 Properties: Bucket: my-photo-bucket Tracing: Active|PassThrough Tags: AppNameTag: ThumbnailApp DepartmentNameTag: ThumbnailDepartmentFrom SAM Version 2016-10-31
  • 21. AWS::Serverless::Function Event source types From SAM Version 2016-10-31 S3 SNS Kinesis | DynamoDB Api Schedule CloudWatchEvent IoTRule AlexaSkill Note: Events are a map of string to Event Source Object Event Source Objects have the following structure: Type: Properties: For Example: Events: MyEventName: Type: S3 Properties: Bucket: my-photo-bucket
  • 22. SAM commands – Package & Deploy Package •Creates a deployment package (.zip file) •Uploads deployment package to an Amazon S3 Bucket •Adds a CodeUri property with S3 URI Deploy •Calls CloudFormation ‘CreateChangeSet’ API •Calls CloudFormation ‘ExecuteChangeSet’ API
  • 23. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS SAM Local 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: • Emulates timeout, memory limits, runtimes https://github.com/awslabs/aws-sam-local
  • 24. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Deploying your applications https://secure.flickr.com/photos/simononly/15386966677
  • 25. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Stage Variables and Lambda Aliases Using Stage Variables in API Gateway together with Lambda function Aliases you can manage a single API configuration and Lambda function for multiple environment stages myLambdaFunction 1 2 3 = prod 4 5 6 = beta 7 8 = dev My First API Stage variable = lambdaAlias Prod lambdaAlias = prod Beta lambdaAlias = beta Dev lambdaAlias = dev
  • 26. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Alias Traffic Shifting & Safe Deployments “By default, an alias points to a single Lambda function version. When the alias is updated to point to a different function version, incoming request traffic in turn instantly points to the updated version.”
  • 27. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Alias Traffic Shifting & Safe Deployments “By default, an alias points to a single Lambda function version. When the alias is updated to point to a different function version, incoming request traffic in turn instantly points to the updated version. This exposes that alias to any potential instabilities introduced by the new version.”
  • 28. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Alias Traffic Shifting & Safe Deployments “By default, an alias points to a single Lambda function version. When the alias is updated to point to a different function version, incoming request traffic in turn instantly points to the updated version. This exposes that alias to any potential instabilities introduced by the new version. To minimize this impact, you can implement the routing-config parameter of the Lambda alias that allows you to point to two different versions of the Lambda function and dictate what percentage of incoming traffic is sent to each version.” – AWS Lambda docs on “Traffic Shifting Using Aliases” aws lambda update-alias --name alias name --function-name function- name --routing-config AdditionalVersionWeights={”6"=0.05}
  • 29. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Alias Traffic Shifting myLambdaFunction 1 2 3 = prod 4 5 6 = prod 5% My First API Stage variable = lambdaAlias Prod lambdaAlias = prod aws lambda update-alias --name prod --function-name myLambdaFunction --routing-config AdditionalVersionWeights={”6"=0.05}
  • 30. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Alias Traffic Shifting myLambdaFunction 5 6 = prod My First API Stage variable = lambdaAlias Prod lambdaAlias = prod aws lambda update-alias --name prod --function-name myLambdaFunction --function-version 6 --routing-config ''
  • 31. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Alias Traffic Shifting & AWS Step Functions Blog link: http://amzn.to/2FjlWA7
  • 32. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. SAM Globals + Safe Deployments Globals: Function: Runtime: nodejs4.3 AutoPublishAlias: !Ref ENVIRONMENT MyLambdaFunction: Type: AWS::Serverless::Function Properties: Handler: index.handler DeploymentPreference: Type: Linear10PercentEvery10Minutes Alarms: # A list of alarms that you want to monitor - !Ref AliasErrorMetricGreaterThanZeroAlarm - !Ref LatestVersionErrorMetricGreaterThanZeroAlarm Hooks: # Validation Lambda functions that are run before & after traffic shifting PreTraffic: !Ref PreTrafficLambdaFunction PostTraffic: !Ref PostTrafficLambdaFunction NEW!
  • 33. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. SAM Globals + Safe Deployments Globals: Function: Runtime: nodejs4.3 AutoPublishAlias: !Ref ENVIRONMENT MyLambdaFunction: Type: AWS::Serverless::Function Properties: Handler: index.handler DeploymentPreference: Type: Linear10PercentEvery10Minutes Alarms: # A list of alarms that you want to monitor - !Ref AliasErrorMetricGreaterThanZeroAlarm - !Ref LatestVersionErrorMetricGreaterThanZeroAlarm Hooks: # Validation Lambda functions that are run before & after traffic shifting PreTraffic: !Ref PreTrafficLambdaFunction PostTraffic: !Ref PostTrafficLambdaFunction NEW!
  • 34. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Alias Traffic Shifting & AWS SAM AutoPublishAlias By adding this property and specifying an alias name, AWS SAM will do the following: • Detect when new code is being deployed based on changes to the Lambda function's Amazon S3 URI. • Create and publish an updated version of that function with the latest code. • Create an alias with a name you provide (unless an alias already exists) and points to the updated version of the Lambda function. Deployment Preference Type Canary10Percent30Minutes Canary10Percent5Minutes Canary10Percent10Minutes Canary10Percent15Minutes Linear10PercentEvery10Minutes Linear10PercentEvery1Minute Linear10PercentEvery2Minutes Linear10PercentEvery3Minutes AllAtOnce In SAM:
  • 35. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda Alias Traffic Shifting & AWS SAM Alarms: # A list of alarms that you want to monitor - !Ref AliasErrorMetricGreaterThanZeroAlarm - !Ref LatestVersionErrorMetricGreaterThanZeroAlarm Hooks: # Validation Lambda functions that are run before & after traffic shifting PreTraffic: !Ref PreTrafficLambdaFunction PostTraffic: !Ref PostTrafficLambdaFunction In SAM: Note: You can specify a maximum of 10 alarms
  • 36. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. NEW: Can deploy AWS Lambda!! Uses AWS SAM to deploy serverless applications Supports Lambda Alias Traffic Shifting enabling canaries and blue|green deployments Can rollback based on CloudWatch Metrics/Alarms Pre/Post-Traffic Triggers can integrate with other services (or even call Lambda functions) AWS CodeDeploy + Lambda NEW!
  • 37. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. CodeDeploy comes with a number of added capabilities: • Custom deployment configurations. Examples: • “Canary 5% for 1 hour” • “Linear 20% every 1 hour” • Notification events via SNS on success/failure/rollback • Console with visibility on deploy status, history, and rollbacks. AWS CodeDeploy + Lambda NEW!
  • 38. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon API Gateway Canary Support Use canary release deployments to gradually roll out new APIs in Amazon API Gateway: • configure percent of traffic to go to a new stage deployment • can test stage settings and variables • API gateway will create additional Amazon CloudWatch Logs group and CloudWatch metrics for the requests handled by the canary deployment API • To rollback: delete the deployment or set percent of traffic to 0 NEW!
  • 39. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon API Gateway Canary Support v1API Clients All publicly and privately accessible endpoints Backends in AWS api.mydomain.com/prod All traffic to currently deployed version
  • 40. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon API Gateway Canary Support API Clients All publicly and privately accessible endpoints Backends in AWS v1 50% v2 50% api.mydomain.com/prod 50% traffic to new deployment of stage, rest to previous version
  • 41. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon API Gateway Canary Support API Clients All publicly and privately accessible endpoints Backends in AWS v1 90% v2 10% api.mydomain.com/prod 10% traffic to new deployment of stage, rest to previous version
  • 42. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon API Gateway Canary Support API Clients All publicly and privately accessible endpoints Backends in AWS v1 90% v2 10% api.mydomain.com/prod 10% traffic to new deployment of stage, rest to previous version No changes to client
  • 43. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon API Gateway Canary Support v2API Clients All publicly and privately accessible endpoints Backends in AWS api.mydomain.com/prod All traffic to new deployed version
  • 44. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon API Gateway Canary Support Interesting use-cases • Explore new technologies in your API backend: • New languages • New frameworks • Try Lambda in place of other HTTP endpoints! • Compare/contrast performance with individual logs and metrics • Migrate an API from on-premises to AWS via endpoint integrations in VPC (new) • API-GW -> Network Load Balancer (NLB) -> on-prem over Direct Connect or VPN connection • Can test method by method or even action by action, no need for an all at once move!
  • 45. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda • Single function is only granularity • Transparent to invoking services • Rollback by setting weight to 0 • Supports automating increments changes via SAM • new version has unique logs & metrics Comparing Lambda vs. API Gateway Canaries API Gateway • Entire stage is maximum granularity • Transparent to clients • Rollback by setting weight to zero or deleting canary • Currently no native automated tooling • new version has unique logs & metrics
  • 46. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda • Single function is only granularity • Transparent to invoking services • Rollback by setting weight to 0 • Supports automating increments changes via SAM • new version has unique logs & metrics Comparing Lambda vs. API Gateway Canaries API Gateway • Entire stage is maximum granularity • Transparent to clients • Rollback by setting weight to zero or deleting canary • Currently no native automated tooling • new version has unique logs & metrics
  • 47. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. CloudWatch Metrics • 7 Built in metrics for Lambda • Can call “put-metric-data” from your function code for custom metrics • New: Function Concurrency • 7 Built in metrics for API- Gateway Metrics and logging are a universal right! CloudWatch Logs • Lambda Logging • Custom logging from your code with your language’s equivalent of console.log() • API Gateway Logging • New: Custom formats • Log Pivots • Build metrics based on log filters
  • 48. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 49. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 50. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 51. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Type: "AWS::CloudWatch::Alarm” Properties: ActionsEnabled: True AlarmActions: - "arn:aws:sns:us-east-1:1234567890abc:MunnsDemoALERT" AlarmDescription: “Error if 5 errors in a single datapoint” AlarmName: "SAM Lambda Error Alarm" ComparisonOperator: "GreaterThanOrEqualToThreshold" Dimensions: - Name: FunctionName Value: ”my-function” - Name: Resource Value: ”my-function" EvaluationPeriods: 1 MetricName: "Errors" Namespace: "AWS/Lambda" Period: 300 Statistic: “Average” Threshold: 5.0
  • 52. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Building your pipeline https://www.flickr.com/photos/seattlemunicipalarchives/12504672623/
  • 53. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Continuous delivery service for fast and reliable application updates Model and visualize your software release process Builds, tests, and deploys your code every time there is a code change Integrates with third-party tools and AWS AWS CodePipeline
  • 54. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. An example minimal Developer’s pipeline: MyBranch-Source Source CodeCommit MyApplication Build test-build-source CodeBuild MyDev-Deploy create-changeset AWS CloudFormation execute-changeset AWS CloudFormation Run-stubs AWS Lambda This pipeline: • Three Stages • Builds code artifact • One Development environment • Uses SAM/CloudFormation to deploy artifact and other AWS resources • Has Lambda custom actions for running my own testing functions
  • 55. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. An example minimal production pipeline: This pipeline: • Five Stages • Builds code artifact • Three deployed to “Environments” • Uses SAM/CloudFormation to deploy artifact and other AWS resources • Has Lambda custom actions for running my own testing functions • Integrates with a 3rd party tool/service • Has a manual approval before deploying to production Source Source CodeCommit MyApplication Build test-build-source CodeBuild Deploy Testing create-changeset AWS CloudFormation execute-changeset AWS CloudFormation Run-stubs AWS Lambda Deploy Staging create-changeset AWS CloudFormation execute-changeset AWS CloudFormation Run-API-test Runscope QA-Sign-off Manual Approval Review Deploy Prod create-changeset AWS CloudFormation execute-changeset AWS CloudFormation Post-Deploy-Slack AWS Lambda
  • 56. Serverless Deployment Patterns Consideration Matrix Consumer impact Rollback Event Model Factors Deployment Speed All at once All at once Redeploy older version Any event model at low concurrency rate Immediate Blue/Green All at once with some level of production environment testing beforehand Revert traffic to OLD Better for async and sync event models at medium concurrency workloads Minutes to hours of validation and then immediate to customers Canaries/ Linear 1-10% typical initial traffic shift, then phased increases or all at once Revert traffic to OLD Better for high concurrency workloads Minutes to hours
  • 57. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Where and what to test? Source MyApplication Build Deploy Testing Deploy Staging Deploy Prod • Code review via Pull Requests • (NEW In CodeCommit) • Lint/syntax check • Unit tests pass • Code successfully compiles • All at once deploy • Mocked/stubbed integration tests • All at once deploy • Tests against real dependencies (potentially against production ones) • Deploy new version and direct all requests to it 1. 2. 3. 4. 5. All at once model
  • 58. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Where and what to test? Source MyApplication Build Deploy Testing Deploy Staging Deploy Prod • Code review via Pull Requests • (NEW In CodeCommit) • Lint/syntax check • Unit tests pass • Code successfully compiles • All at once deploy • Mocked/stubbed integration tests • All at once deploy • Tests against dependencies • Deploy green version • Run tests against green & validate • Direct 100% to green 1. 2. 3. 4. 5. Blue/Green model
  • 59. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Where and what to test? Source MyApplication Build Deploy Testing Deploy Staging Deploy Prod • Code review via Pull Requests • (NEW In CodeCommit) • Lint/syntax check • Unit tests pass • Code successfully compiles • All at once deploy • Mocked/stubbed integration tests • All at once deploy • Tests against dependencies • Deploy canaries • Complete wait period successfully • Deploy 100% 1. 2. 3. 4. 5. Canary model
  • 60. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Environments, Stages, Versioning, & Canaries? A few best practices: 1. Use blue|green or canaries for production deployments with a rollback as automated as possible 2. In Lambda Versioning is useful if you need to support multiple versions to multiple consumers/invocation points 3. In API-Gateway Stages work similarly and are useful if you need to support multiple API versions 4. Try to always have separate “stacks” for Development, Testing, Staging, Production environments 1. Do not use Stages or Versioning for this 2. Think about having different accounts all together for different environments
  • 61. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. FIN, ACK With the recent feature releases you can easily deploy Lambda functions in a safe and controlled manner! Some key takeaways: • automatic rollbacks should be your first line of recovery for deployment related issues • different event models and different workload sizes can cause you to use different deployment patterns • decide on the most key metric to rollback or fail a deployment on related to how a bad deployment might impact your customers • AWS SAM + AWS CodeDeploy enable you to easily do all at once, blue|green, and canary based deployments for serverless applications!
  • 62. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. aws.amazon.com/serverless
  • 63. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Chris Munns munns@amazon.com @chrismunnshttps://www.flickr.com/photos/theredproject/3302110152/
  • 64. © 2018, Amazon Web Services, Inc. or its Affiliates. All rights reserved. ? https://secure.flickr.com/photos/dullhunk/202872717/