Upload
others
View
22
Download
0
Embed Size (px)
Citation preview
Continuous deployment of Serverless resourcesSergii Pavlenko | 09 Sep 2019Smaato Inc.
Community Day 2019 Sponsors
Continuous deployment of Serverless resources
Sergii Pavlenko, Smaato Inc.Sep 9, 2019
Agenda
I What is Serverless?
II Traditional vs Lambda Deployment
III AWS SAM
IV AWS SAM Deployment Types
V Demo
VI Things To Keep In Mind
VII AWS SAM Alternatives
Copyright © 2019 Smaato, Inc. All Rights Reserved. 3
VIII Conclusions
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
About the speaker
4
Sergii PavlenkoSenior Software Engineer15 years in ITServerless Advocate
Smaato Inc.Smaato is the leading global mobile RTB ad
exchange (SMX) helping mobile app developers and publishers increase ad revenues worldwide.
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved. 5
Serverless
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
What is Serverless
6
Serverless principles
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved. 7
Traditional Deployment
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Zero Downtime deployment
8
Zero downtime deployment overview
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Zero Downtime deployment
9
Blue Green Deployment
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Zero Downtime deployment
10
Route 53Update DNS routes
Load BalancerSwap Auto Scaling
Groups
Launch Configuration
Auto Scaling GroupUpdate Launch Configuration
Elastic BeanstalkSwap URLs
OpsWorksCloning Stacks
CloudformationUpdate Policies
Zero downtime deployment strategies in AWS resources
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved. 11
AWS Lambda Deployment
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Lambda deployment
12
AWS Lambda deployment techniques
Two main attributes for safe deployment• versions• aliases
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Lambda deployment with manual traffic shifting
13
Using Aliases to manage Lambda function versions
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Lambda deployment with manual traffic shifting
14
Using Aliases to manage Lambda function versions
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Lambda deployment with manual traffic shifting
15
Manual traffic shifting using CLI
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved. 16
AWS SAM
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
AWS Serverless Application Model
17
AWS SAM is a model used to define serverless applications on AWS
AWS SAM template specification
AWS SAM command line interface (AWS SAM CLI)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
AWS Serverless Application Model
18
Single-deployment configuration
Extension of AWS CloudFormation
Built-in best practices
Local debugging and testing
Deep integration with development tools
AWS SAM benefits
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
SAM Cloudformation Extension
19
SAM templateAWSTemplateFormatVersion: 2010-09-09Transform: AWS::Serverless-2016-10-31Resources: MyFunction: Type: AWS::Serverless::Function Properties: CodeUri: / Handler: worker_function.lambda_handler Runtime: python3.7 AutoPublishAlias: live DeploymentPreference: Type: Canary10Percent5Minutes Alarms: - !Ref ErrorMetricGreaterThanZeroAlarm Hooks: PreTraffic: !Ref PreTrafficLambdaFunction PostTraffic: !Ref PostTrafficLambdaFunction Policies: - AmazonS3ReadOnlyAccess Events: GetResource: Type: Api Properties: Path: /get Method: GET
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
SAM Deployment Preference
20
SAM templateAWSTemplateFormatVersion: 2010-09-09Transform: AWS::Serverless-2016-10-31Resources: MyFunction: Type: AWS::Serverless::Function Properties: CodeUri: / Handler: worker_function.lambda_handler Runtime: python3.7 AutoPublishAlias: live DeploymentPreference: Type: Canary10Percent5Minutes Alarms: - !Ref ErrorMetricGreaterThanZeroAlarm Hooks: PreTraffic: !Ref PreTrafficLambdaFunction PostTraffic: !Ref PostTrafficLambdaFunction Policies: - AmazonS3ReadOnlyAccess Events: GetResource: Type: Api Properties: Path: /get Method: GET
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Traffic routing with Step Functions
21
StartAt: PreTrafficStates: PreTraffic: Type: Task Resource: !Sub "${PreTrafficLambdaFunction.Arn}" Next: IncreaseTrafficShifting IncreaseTrafficShifting: Type: Task Resource: !Sub "${IncreaseTrafficShiftingFunction.Arn}" Next: Wait Wait: Type: Wait Seconds: 600 Next: CheckFailures CheckFailures: Type: Choice Choices: - Variable: "$.failures" NumericEquals: 0 Next: IncreaseTrafficShifting - Variable: "$.percentage" NumericEquals: 100 Next: PostTraffic Default: Fail PostTraffic: Type: Task Resource: !Sub "${PostTrafficLambdaFunction.Arn}"
State Machine in nutshell
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Automated Lambda deployment with AWS SAM
22
AWS SAM Deployment Types
Canary
Linear
All-at-once
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Automated Lambda deployment with AWS SAM
23
Canary deployment
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Automated Lambda deployment with AWS SAM
24
Linear deployment
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved. 25
DEMO
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Demo
26
Classic Serverless Web Application
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved. 27
Things to keep in mind
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Deployment Watchouts
28
Route users instead of requests
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Deployment Watchouts
29
New version - new container
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Deployment Watchouts
30
False positive rollbacksFalse negative validations
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Deployment Watchouts
31
Complex invocations
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Amazon API Gateway versioning
32
Classic path-based versioning
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Amazon API Gateway versioning
33
API Gateway path-based versioning configuring
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved. 34
AWS SAM Alternatives
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Alternatives
35
Serverless
plugins: - serverless-plugin-aws-alerts - serverless-plugin-canary-deployments
functions: worker-function: deploymentSettings: type: Canary10Percent5Minutes alias: live preTrafficHook: preHook postTrafficHook: postHook alarms: - funcAlarm
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Alternatives
36
Terraform
resource "aws_codedeploy_deployment_config" "config" { compute_platform = "Lambda"
traffic_routing_config { type = "TimeBasedCanary"
time_based_canary { interval = 10 percentage = 5 } }}
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Conclusions
37
Conclusions• zero downtime deployment is better than scheduled
deployment• use versions and aliases for instant update/rollback• weighted aliases re-routing is working out of the box• automated shifting traffic is enough for the most cases• need to be careful in particular cases
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Links
38
Links• What Is the AWS Serverless Application Model (AWS SAM)?• AWS Serverless Application Model (AWS SAM)• AWS SAM CLI• What Is CodeDeploy?• Traffic Shifting Using Aliases• Gradual Code Deployment• quickstart-codepipeline-bluegreen-deployment• Blue/Green Deployments on AWS
San Francisco, CAT: +1 (650) [email protected]
New York City, NYTel: +1 (646) [email protected]
Hamburg, GermanyT: +49 (40) 3480 [email protected]
Berlin, GermanyT: +49 (40) 3480 [email protected]
Singapore, SGT: +65 6336 [email protected]
Shanghai, ChinaT: +86 21 6263 [email protected]
Thank You.ABOUT SMAATOSmaato, the global in-app advertising platform, drives the technology that keeps apps free. Smaato’s full-featured mobile ad server empowers apps of all sizes to reach their full monetization potential by connecting them with the world’s top advertisers. The Smaato SDK provides publishers with seamless integration and maximum control of their inventory. Founded in 2005, Smaato is headquartered in San Francisco, California, with additional offices in Berlin, Hamburg, New York, Shanghai, and Singapore. Learn more at www.smaato.com.