resources Continuous deployment of Serverless · AWS Serverless Application Model 18...
Transcript of resources Continuous deployment of Serverless · AWS Serverless Application Model 18...
![Page 1: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/1.jpg)
Continuous deployment of Serverless resourcesSergii Pavlenko | 09 Sep 2019Smaato Inc.
Community Day 2019 Sponsors
![Page 2: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/2.jpg)
Continuous deployment of Serverless resources
Sergii Pavlenko, Smaato Inc.Sep 9, 2019
![Page 3: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/3.jpg)
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
![Page 4: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/4.jpg)
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.
![Page 5: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/5.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved. 5
Serverless
![Page 6: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/6.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
What is Serverless
6
Serverless principles
![Page 7: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/7.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved. 7
Traditional Deployment
![Page 8: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/8.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Zero Downtime deployment
8
Zero downtime deployment overview
![Page 9: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/9.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Zero Downtime deployment
9
Blue Green Deployment
![Page 10: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/10.jpg)
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
![Page 11: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/11.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved. 11
AWS Lambda Deployment
![Page 12: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/12.jpg)
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
![Page 13: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/13.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Lambda deployment with manual traffic shifting
13
Using Aliases to manage Lambda function versions
![Page 14: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/14.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Lambda deployment with manual traffic shifting
14
Using Aliases to manage Lambda function versions
![Page 15: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/15.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Lambda deployment with manual traffic shifting
15
Manual traffic shifting using CLI
![Page 16: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/16.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved. 16
AWS SAM
![Page 17: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/17.jpg)
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)
![Page 18: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/18.jpg)
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
![Page 19: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/19.jpg)
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
![Page 20: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/20.jpg)
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
![Page 21: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/21.jpg)
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
![Page 22: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/22.jpg)
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
![Page 23: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/23.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Automated Lambda deployment with AWS SAM
23
Canary deployment
![Page 24: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/24.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Automated Lambda deployment with AWS SAM
24
Linear deployment
![Page 25: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/25.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved. 25
DEMO
![Page 26: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/26.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Demo
26
Classic Serverless Web Application
![Page 27: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/27.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved. 27
Things to keep in mind
![Page 28: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/28.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Deployment Watchouts
28
Route users instead of requests
![Page 29: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/29.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Deployment Watchouts
29
New version - new container
![Page 30: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/30.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Deployment Watchouts
30
False positive rollbacksFalse negative validations
![Page 31: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/31.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Deployment Watchouts
31
Complex invocations
![Page 32: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/32.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Amazon API Gateway versioning
32
Classic path-based versioning
![Page 33: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/33.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved.
Amazon API Gateway versioning
33
API Gateway path-based versioning configuring
![Page 34: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/34.jpg)
Version 01.01
Copyright © 2019 Smaato, Inc. All Rights Reserved. 34
AWS SAM Alternatives
![Page 35: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/35.jpg)
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
![Page 36: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/36.jpg)
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 } }}
![Page 37: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/37.jpg)
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
![Page 38: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/38.jpg)
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
![Page 39: resources Continuous deployment of Serverless · AWS Serverless Application Model 18 Single-deployment configuration Extension of AWS CloudFormation ... Traffic routing with Step](https://reader034.fdocuments.net/reader034/viewer/2022042222/5ec8a0fda7c3652de25c0bbf/html5/thumbnails/39.jpg)
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.