Slide 1

Slide 1 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Gunnar Grosch Senior Developer Advocate, AWS @gunnargrosch CI/CD for serverless applications

Slide 2

Slide 2 text

© 2021, Amazon Web Services, Inc. or its Affiliates. What is CI/CD? CI: Continuous integration CD: Continuous delivery or CD: Continuous deployment

Slide 3

Slide 3 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Stages of the software release process Source Build Test Production

Slide 4

Slide 4 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Stages of the software release process Source Build Test Production Developers’ version – review and commit code changes

Slide 5

Slide 5 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Stages of the software release process Source Build Test Production Build tasks and unit testing Developers’ version – review and commit code changes

Slide 6

Slide 6 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Stages of the software release process Source Build Test Production Deploy to testing environments and run integration tests Developers’ version – review and commit code changes Build tasks and unit testing

Slide 7

Slide 7 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Stages of the software release process Source Build Test Production Deploy to production environment Developers’ version – review and commit code changes Build tasks and unit testing Deploy to testing environments and run integration tests

Slide 8

Slide 8 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Stages of the software release process Source Build Test Production Continuous integration

Slide 9

Slide 9 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Stages of the software release process Source Build Test Production Continuous integration Continuous delivery Approved deploy

Slide 10

Slide 10 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Stages of the software release process Source Build Test Production Continuous deployment Continuous integration Continuous delivery Automated deploy Approved deploy

Slide 11

Slide 11 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Choosing the right tools

Slide 12

Slide 12 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS CodePipeline • 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 • https://aws.amazon.com/codepipeline/

Slide 13

Slide 13 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Example of minimal developer’s pipeline • Three stages • Builds code artifact • One development environment • Uses AWS SAM/AWS CloudFormation to deploy artifact and other AWS resources • Has Lambda custom actions for testing functions Source Source GitHub i Build test-build-source CodeBuild i MyDev-Deploy create-changeset CloudFormation i execute-changeset CloudFormation i Run-stubs Lambda i

Slide 14

Slide 14 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Example of production pipeline • Five stages • Builds code artifact • Three deployed to “environments” • Uses AWS SAM / AWS CloudFormation to deploy artifact and other AWS resources • AWS Lambda custom actions for testing functions • Integrates with a third-party tool / service • Has a manual approval before deploying to production Source Source GitHub i Build test-build-source CodeBuild i Deploy-Testing create-changeset CloudFormation i execute-changeset CloudFormation i Run-stubs Lambda i Deploy-Staging Deploy-Prod create-changeset CloudFormation i execute-changeset CloudFormation i Post-Deploy-Stack Lambda i create-changeset CloudFormation i execute-changeset CloudFormation i QA-Sign-Off Manual approval i Review Run-API-test Runscope i

Slide 15

Slide 15 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Best practice Keep one environment per AWS account Source Source GitHub i Build test-build-source CodeBuild i Deploy-Testing create-changeset CloudFormation i execute-changeset CloudFormation i Run-stubs Lambda i Deploy-Staging Deploy-Prod create-changeset CloudFormation i execute-changeset CloudFormation i Post-Deploy-Stack Lambda i create-changeset CloudFormation i execute-changeset CloudFormation i QA-Sign-Off Manual approval i Review Run-API-test Runscope i Dev account Staging account Production account

Slide 16

Slide 16 text

© 2021, Amazon Web Services, Inc. or its Affiliates. CodePipeline demo

Slide 17

Slide 17 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS CodePipeline: Supported sources A U T O M A T I C A L L Y K I C K O F F R E L E A S E A N D P U L L L A T E S T S O U R C E C O D E Pick object or folder Amazon Simple Storage Service (Amazon S3) Pick Docker tag Amazon Elastic Container Registry (Amazon ECR) Pick branch AWS CodeCommit GitHub

Slide 18

Slide 18 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Release process stages Source Build Test Production Infrastructure Code

Slide 19

Slide 19 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Infrastructure as code

Slide 20

Slide 20 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS CloudFormation • Infrastructure as code • Provides a common language for you to describe and provision all the infrastructure resources in your cloud environment • Build and rebuild your infrastructure and applications, without having to perform manual actions or write custom scripts • https://aws.amazon.com/cloudformation/

Slide 21

Slide 21 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS Serverless Application Model (AWS SAM) • Open source framework for building serverless applications on AWS • Shorthand syntax to express functions, APIs, databases, and event source mappings • Transforms and expands SAM syntax into AWS CloudFormation syntax on deployment • Supports all AWS CloudFormation resource types https://aws.amazon.com/serverless/sam/

Slide 22

Slide 22 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS SAM template AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: MySimpleTableFunction: Type: AWS::Serverless::Function Properties: Handler: mySimpleTableFunction.handler Runtime: nodejs12.x CodeUri: ./functions Policies: - DynamoDBReadPolicy: TableName: !Ref MySimpleTable Events: MySimpleFunctionApi: Type: Api Properties: Path: /simpleTable Method: GET MySimpleTable: Type: AWS::Serverless::SimpleTable

Slide 23

Slide 23 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS SAM template AWS Cloud Amazon API Gateway Lambda function Table Role === To become this Allowing this AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: MySimpleTableFunction: Type: AWS::Serverless::Function Properties: Handler: mySimpleTableFunction.handler Runtime: nodejs12.x CodeUri: ./functions Policies: - DynamoDBReadPolicy: TableName: !Ref MySimpleTable Events: MySimpleFunctionApi: Type: Api Properties: Path: /simpleTable Method: GET MySimpleTable: Type: AWS::Serverless::SimpleTable

Slide 24

Slide 24 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: MySimpleTableFunction: Type: AWS::Serverless::Function Properties: Handler: mySimpleTableFunction.handler Runtime: nodejs12.x CodeUri: ./functions Policies: - DynamoDBReadPolicy: TableName: !Ref MySimpleTable Events: MySimpleFunctionApi: Type: Api Properties: Path: /simpleTable Method: GET MySimpleTable: Type: AWS::Serverless::SimpleTable AWS SAM template Tells AWS CloudFormation that this is a SAM template it needs to “transform”

Slide 25

Slide 25 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: MySimpleTableFunction: Type: AWS::Serverless::Function Properties: Handler: mySimpleTableFunction.handler Runtime: nodejs12.x CodeUri: ./functions Policies: - DynamoDBReadPolicy: TableName: !Ref MySimpleTable Events: MySimpleFunctionApi: Type: Api Properties: Path: /simpleTable Method: GET MySimpleTable: Type: AWS::Serverless::SimpleTable AWS SAM template Just 20 lines to create: • Lambda function • IAM role • API gateway

Slide 26

Slide 26 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: MySimpleTableFunction: Type: AWS::Serverless::Function Properties: Handler: mySimpleTableFunction.handler Runtime: nodejs12.x CodeUri: ./functions Policies: - DynamoDBReadPolicy: TableName: !Ref MySimpleTable Events: MySimpleFunctionApi: Type: Api Properties: Path: /simpleTable Method: GET MySimpleTable: Type: AWS::Serverless::SimpleTable AWS SAM template Function configuration

Slide 27

Slide 27 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: MySimpleTableFunction: Type: AWS::Serverless::Function Properties: Handler: mySimpleTableFunction.handler Runtime: nodejs12.x CodeUri: ./functions Policies: - DynamoDBReadPolicy: TableName: !Ref MySimpleTable Events: MySimpleFunctionApi: Type: Api Properties: Path: /simpleTable Method: GET MySimpleTable: Type: AWS::Serverless::SimpleTable AWS SAM template Permissions for the function

Slide 28

Slide 28 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: MySimpleTableFunction: Type: AWS::Serverless::Function Properties: Handler: mySimpleTableFunction.handler Runtime: nodejs12.x CodeUri: ./functions Policies: - DynamoDBReadPolicy: TableName: !Ref MySimpleTable Events: MySimpleFunctionApi: Type: Api Properties: Path: /simpleTable Method: GET MySimpleTable: Type: AWS::Serverless::SimpleTable AWS SAM policy templates Policies: - CloudWatchPutMetricPolicy: {} Policies: - DynamoDBReadPolicy: TableName: !Ref MySimpleTable

Slide 29

Slide 29 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: MySimpleTableFunction: Type: AWS::Serverless::Function Properties: Handler: mySimpleTableFunction.handler Runtime: nodejs12.x CodeUri: ./functions Policies: - DynamoDBReadPolicy: TableName: !Ref MySimpleTable Events: MySimpleFunctionApi: Type: Api Properties: Path: /simpleTable Method: GET MySimpleTable: Type: AWS::Serverless::SimpleTable AWS SAM policy templates All the available policies can be found here: http://bit.ly/sam-policy-template

Slide 30

Slide 30 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: MySimpleTableFunction: Type: AWS::Serverless::Function Properties: Handler: mySimpleTableFunction.handler Runtime: nodejs12.x CodeUri: ./functions Policies: - DynamoDBReadPolicy: TableName: !Ref MySimpleTable Events: MySimpleFunctionApi: Type: Api Properties: Path: /simpleTable Method: GET MySimpleTable: Type: AWS::Serverless::SimpleTable AWS SAM template API gateway

Slide 31

Slide 31 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWSTemplateFormatVersion: '2010-09-09’ Transform: AWS::Serverless-2016-10-31 Resources: MySimpleTableFunction: Type: AWS::Serverless::Function Properties: Handler: mySimpleTableFunction.handler Runtime: nodejs12.x CodeUri: ./functions Policies: - DynamoDBReadPolicy: TableName: !Ref MySimpleTable Events: MySimpleFunctionApi: Type: Api Properties: Path: /simpleTable Method: GET MySimpleTable: Type: AWS::Serverless::SimpleTable AWS SAM template Creates an Amazon DynamoDB table with 5 read / write units

Slide 32

Slide 32 text

© 2021, Amazon Web Services, Inc. or its Affiliates. One artifact – Multiple stages DEV STAGE PROD

Slide 33

Slide 33 text

© 2021, Amazon Web Services, Inc. or its Affiliates. One artifact – Multiple stages I N A W S S A M T E M P L A T E Parameters: MyEnvironment: Type: String Default: dev AllowedValues: - dev - staging - prod Mappings: ResourcesName: dev: tableName: MyDynamoDBTable-dev staging: tableName: MyDynamoDBTable-staging prod: tableName: MyDynamoDBTable-prod Resources: MyDynamoDBTable: Type: "AWS::DynamoDB::Table" Properties: . . . TableName: !FindInMap [ResourcesName, !Ref MyEnvironment, tableName]

Slide 34

Slide 34 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Parameters: MyEnvironment: Type: String Default: dev AllowedValues: - dev - staging - prod Mappings: ResourcesName: dev: tableName: MyDynamoDBTable-dev staging: tableName: MyDynamoDBTable-staging prod: tableName: MyDynamoDBTable-prod Resources: MyDynamoDBTable: Type: "AWS::DynamoDB::Table" Properties: . . . TableName: !FindInMap [ResourcesName, !Ref MyEnvironment, tableName] One artifact – Multiple stages I N A W S S A M T E M P L A T E

Slide 35

Slide 35 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Parameters: MyEnvironment: Type: String Default: dev AllowedValues: - dev - staging - prod Mappings: ResourcesName: dev: tableName: MyDynamoDBTable-dev staging: tableName: MyDynamoDBTable-staging prod: tableName: MyDynamoDBTable-prod Resources: MyDynamoDBTable: Type: "AWS::DynamoDB::Table" Properties: . . . TableName: !FindInMap [ResourcesName, !Ref MyEnvironment, tableName] One artifact – Multiple stages I N A W S S A M T E M P L A T E

Slide 36

Slide 36 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Parameters: MyEnvironment: Type: String Default: dev AllowedValues: - dev - staging - prod Mappings: ResourcesName: dev: tableName: MyDynamoDBTable-dev staging: tableName: MyDynamoDBTable-staging prod: tableName: MyDynamoDBTable-prod Resources: MyDynamoDBTable: Type: "AWS::DynamoDB::Table" Properties: . . . TableName: !FindInMap [ResourcesName, !Ref MyEnvironment, tableName] One artifact – Multiple stages I N A W S S A M T E M P L A T E

Slide 37

Slide 37 text

© 2021, Amazon Web Services, Inc. or its Affiliates. One artifact – Multiple stages I N A W S C O D E P I P E L I N E We need to pass the stage name as a parameter when we create the AWS CloudFormation change set https://amzn.to/3lKXCfR

Slide 38

Slide 38 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS Lambda environment variables I N A W S S A M T E M P L A T E MySimpleFunction: Type: "AWS::Serverless::Function" Properties: Handler: mySimpleFunction.handler Policies: - DynamoDBCrudPolicy: TableName: !Ref MyDynamoDBTable Environment: Variables: TABLE_NAME: !Ref MyDynamoDBTable Events: MySimpleFunctionAPI: Type: Api Properties: RestApiId: !Ref MyApi Path: /simple Method: GET

Slide 39

Slide 39 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS Lambda environment variables I N T H E H A N D L E R O F T H E F U N C T I O N MySimpleFunction: Type: "AWS::Serverless::Function" Properties: Handler: mySimpleFunction.handler Policies: - DynamoDBCrudPolicy: TableName: !Ref MyDynamoDBTable Environment: Variables: TABLE_NAME: !Ref MyDynamoDBTable Events: MySimpleFunctionAPI: Type: Api Properties: RestApiId: !Ref MyApi Path: /simple Method: GET 'use strict'; const TABLE_NAME = process.env.TABLE_NAME; module.exports.getItem = async (propertyId, sortKey) => { console.log('getItem'); ...

Slide 40

Slide 40 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Function code

Slide 41

Slide 41 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Release process stages Source Build Test Production Code Infrastructure .zip Container images

Slide 42

Slide 42 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Function code as container image • Use your favorite tools to build your apps • Pack function code and dependencies as a container image up to 10 GB • Lambda function only runs when triggered • Best of two worlds • Serverless operational simplicity • Flexibility of containers

Slide 43

Slide 43 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS SAM INIT $sam init Which template source would you like to use? 1 - AWS Quick Start Templates 2 - Custom Template Location Choice: 1 What package type would you like to use? 1 - Zip (artifact is a zip uploaded to S3) 2 - Image (artifact is an image uploaded to an ECR image repository) Package type: 2

Slide 44

Slide 44 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS SAM INIT Which base image would you like to use? 1 - amazon/nodejs12.x-base 2 - amazon/nodejs10.x-base 3 - amazon/python3.8-base 4 - amazon/python3.7-base 5 - amazon/python3.6-base 6 - amazon/python2.7-base 7 - amazon/ruby2.7-base 8 - amazon/ruby2.5-base 9 - amazon/go1.x-base 10 - amazon/java11-base 11 - amazon/java8.al2-base 12 - amazon/java8-base 13 - amazon/dotnetcore3.1-base 14 - amazon/dotnetcore2.1-base Project name [sam-app]: sam-lambda-containers Cloning app templates from https://github.com/awslabs/aws-sam-cli-app- templates.git ----------------------- Generating application: ----------------------- Name: sam-lambda-containers Base Image: amazon/nodejs12.x-base Dependency Manager: npm Output Directory: . Next steps can be found in the README file at ./sam-lambda-containers/README.md Base image: 1

Slide 45

Slide 45 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Function code: Docker config FROM 628053151772.dkr.ecr.sa-east- 1.amazonaws.com/awslambda/nodejs12.x-runtime:beta COPY app.js package.json ./ RUN npm install # Command can be overwritten by providing a different command in the template directly. CMD ["app.lambdaHandler"]

Slide 46

Slide 46 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS SAM with container images In the template.yml Resources: MyFunction: Type: 'AWS::Serverless::Function’ Properties: PackageType: Image ImageUri: '123456789012.dkr.ecr.us-west-2.amazonaws.com/my-function:latest'

Slide 47

Slide 47 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Container image demo

Slide 48

Slide 48 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Release process stages Source Build Test Production

Slide 49

Slide 49 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS CodeBuild • Fully managed build service that can compile source code, run tests, and produce software packages • Scales continuously and processes multiple builds concurrently • No build servers to manage • Pay by the minute, for only the compute resources you use • https://aws.amazon.com/codebuild/

Slide 50

Slide 50 text

© 2021, Amazon Web Services, Inc. or its Affiliates. phases: install: commands: - pip install --upgrade pip - pip install pipenv –user - pipenv install awscli aws-sam-cli - npm install pre_build: commands: - eslint *.js - npm test build: commands: - sam build post_build: commands: - sam package –template-file template.yaml –s3-bucket $BUCKET_NAME –output-template packaged.yaml artifacts: type: zip files: - packaged.yaml Lambda buildspec using SAM CLI A W S C O D E B U I L D

Slide 51

Slide 51 text

© 2021, Amazon Web Services, Inc. or its Affiliates. phases: install: commands: - pip install --upgrade pip - pip install pipenv –user - pipenv install awscli aws-sam-cli - npm install pre_build: commands: - eslint *.js - npm test build: commands: - sam build post_build: commands: - sam package –template-file template.yaml –s3-bucket $BUCKET_NAME –output-template packaged.yaml artifacts: type: zip files: - packaged.yaml Lambda buildspec using SAM CLI A W S C O D E B U I L D Use install phase to install packages or any prereqs you may need throughout the build

Slide 52

Slide 52 text

© 2021, Amazon Web Services, Inc. or its Affiliates. phases: install: commands: - pip install --upgrade pip - pip install pipenv –user - pipenv install awscli aws-sam-cli - npm install pre_build: commands: - eslint *.js - npm test build: commands: - sam build post_build: commands: - sam package –template-file template.yaml –s3-bucket $BUCKET_NAME –output-template packaged.yaml artifacts: type: zip files: - packaged.yaml Lambda buildspec using SAM CLI A W S C O D E B U I L D Use pre-build phase to run unit tests

Slide 53

Slide 53 text

© 2021, Amazon Web Services, Inc. or its Affiliates. phases: install: commands: - pip install --upgrade pip - pip install pipenv –user - pipenv install awscli aws-sam-cli - npm install pre_build: commands: - eslint *.js - npm test build: commands: - sam build post_build: commands: - sam package –template-file template.yaml –s3-bucket $BUCKET_NAME –output-template packaged.yaml artifacts: type: zip files: - packaged.yaml Lambda buildspec using SAM CLI A W S C O D E B U I L D In the build phase, we build the project using AWS SAM

Slide 54

Slide 54 text

© 2021, Amazon Web Services, Inc. or its Affiliates. phases: install: commands: - pip install --upgrade pip - pip install pipenv –user - pipenv install awscli aws-sam-cli - npm install pre_build: commands: - eslint *.js - npm test build: commands: - sam build post_build: commands: - sam package –template-file template.yaml –s3-bucket $BUCKET_NAME –output-template packaged.yaml artifacts: type: zip files: - packaged.yaml Lambda buildspec using SAM CLI A W S C O D E B U I L D Use post-build for creating the package of the artifact

Slide 55

Slide 55 text

© 2021, Amazon Web Services, Inc. or its Affiliates. phases: install: commands: - pip install --upgrade pip - pip install pipenv –user - pipenv install awscli aws-sam-cli - npm install pre_build: commands: - eslint *.js - npm test build: commands: - sam build post_build: commands: - sam package –template-file template.yaml –s3-bucket $BUCKET_NAME –output-template packaged.yaml artifacts: type: zip files: - packaged.yaml Lambda buildspec using SAM CLI A W S C O D E B U I L D Where AWS CodeBuild can find the output artifacts

Slide 56

Slide 56 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Lambda buildspec using SAM CLI and container images A W S C O D E B U I L D post_build: commands: - sam package –image-repository –output-template-file packaged.yaml –resolve-s3 ONLY CHANGE NEEDED Package with the ECR image

Slide 57

Slide 57 text

© 2021, Amazon Web Services, Inc. or its Affiliates. CodeBuild demo

Slide 58

Slide 58 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Release process stages Source Build Test Production

Slide 59

Slide 59 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Where and what to test • Code review via pull request • Lint / syntax check • Unit test pass • Code successfully compiles • Application deploys successfully • Mocked / stubbed integration tests • Application deploys successfully • Test against real services (potentially against production dependencies) • Run pre-traffic Lambda tests • Deploy canaries • Complete wait period successfully • Deploy 100% • Run post-traffic Lambda tests Source Source CodeCommit i Build test-build-source CodeBuild i Deploy-Testing create-changeset CloudFormation i execute-changeset CloudFormation i Run-stubs Lambda i Deploy-Staging Deploy-Prod create-changeset CloudFormation i execute-changeset CloudFormation i Post-Deploy-Stack Lambda i create-changeset CloudFormation i execute-changeset CloudFormation i QA-Sign-Off Manual approval i Review Run-API-test Runscope i

Slide 60

Slide 60 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS Lambda to perform integration tests exports.handler = async (event, context) => { let jobId = event["CodePipeline.job"].id; // DO SOME INTEGRATION TESTS if (testsPassed) { let params = { jobId: jobId }; return codepipeline.putJobSuccessResult(params).promise(data => { context.succeed('Test passed'); }).catch(error => { context.fail(error); }); } else { let params = { jobId: jobId, failureDetails: { message: JSON.stringify('Test failed’), type: 'JobFailed’, externalExecutionId: context.invokeid } }; return codepipeline.putJobFailureResult(params).promise(data => { context.fail(message); }); } };

Slide 61

Slide 61 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS Lambda to perform integration tests exports.handler = async (event, context) => { let jobId = event["CodePipeline.job"].id; // DO SOME INTEGRATION TESTS if (testsPassed) { let params = { jobId: jobId }; return codepipeline.putJobSuccessResult(params).promise(data => { context.succeed('Test passed'); }).catch(error => { context.fail(error); }); } else { let params = { jobId: jobId, failureDetails: { message: JSON.stringify('Test failed’), type: 'JobFailed’, externalExecutionId: context.invokeid } }; return codepipeline.putJobFailureResult(params).promise(data => { context.fail(message); }); } }; Write some integration tests

Slide 62

Slide 62 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS Lambda to perform integration tests exports.handler = async (event, context) => { let jobId = event["CodePipeline.job"].id; // DO SOME INTEGRATION TESTS if (testsPassed) { let params = { jobId: jobId }; return codepipeline.putJobSuccessResult(params).promise(data => { context.succeed('Test passed'); }).catch(error => { context.fail(error); }); } else { let params = { jobId: jobId, failureDetails: { message: JSON.stringify('Test failed’), type: 'JobFailed’, externalExecutionId: context.invokeid } }; return codepipeline.putJobFailureResult(params).promise(data => { context.fail(message); }); } }; Needs to call the putJobSuccessResult

Slide 63

Slide 63 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS Lambda to perform integration tests exports.handler = async (event, context) => { let jobId = event["CodePipeline.job"].id; // DO SOME INTEGRATION TESTS if (testsPassed) { let params = { jobId: jobId }; return codepipeline.putJobSuccessResult(params).promise(data => { context.succeed('Test passed'); }).catch(error => { context.fail(error); }); } else { let params = { jobId: jobId, failureDetails: { message: JSON.stringify('Test failed’), type: 'JobFailed’, externalExecutionId: context.invokeid } }; return codepipeline.putJobFailureResult(params).promise(data => { context.fail(message); }); } }; Needs to call the putJobFailureResult

Slide 64

Slide 64 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS Lambda to perform integration tests exports.handler = async (event, context) => { let jobId = event["CodePipeline.job"].id; // DO SOME INTEGRATION TESTS if (testsPassed) { let params = { jobId: jobId }; return codepipeline.putJobSuccessResult(params).promise(data => { context.succeed('Test passed'); }).catch(error => { context.fail(error); }); } else { let params = { jobId: jobId, failureDetails: { message: JSON.stringify('Test failed’), type: 'JobFailed’, externalExecutionId: context.invokeid } }; return codepipeline.putJobFailureResult(params).promise(data => { context.fail(message); }); } }; Find more information on how to configure this here: https://amzn.to/2SVWZlW

Slide 65

Slide 65 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS CodeDeploy • Automate code deployments to any instance and AWS Lambda • Handle the complexity of updating your applications • Avoid downtime during application deployment • Roll back automatically if failure is detected • Deploy to Amazon EC2, AWS Lambda, AWS Fargate, Amazon EC2, or on-premises servers

Slide 66

Slide 66 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Safe deployments Canary10Percent30Minutes Canary10Percent5Minutes Canary10Percent10Minutes Canary10Percent15Minutes Linear10PercentEvery10Minutes Linear10PercentEvery1Minute Linear10PercentEvery2Minutes Linear10PercentEvery3Minutes AllAtOnce BeforeAllowTraffic AfterAllowTraffic AllowTraffic Deployment preference

Slide 67

Slide 67 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Lambda canary deployment A W S C O D E D E P L O Y API gateway Lambda function weighted alias “live” v1 Lambda function code 100%

Slide 68

Slide 68 text

© 2021, Amazon Web Services, Inc. or its Affiliates. API gateway Lambda function weighted alias “live” v1 code 100% Run PreTraffic hook against v2 code before it receives traffic v2 code 0% Lambda canary deployment A W S C O D E D E P L O Y

Slide 69

Slide 69 text

© 2021, Amazon Web Services, Inc. or its Affiliates. API gateway Lambda function weighted alias “live” v1 code 90% Wait 10 minutes, roll back in case of alarm v2 code 10% Lambda canary deployment A W S C O D E D E P L O Y

Slide 70

Slide 70 text

© 2021, Amazon Web Services, Inc. or its Affiliates. API gateway Lambda function weighted alias “live” v1 code 0% Run PostTraffic hook and complete deployment v2 code 100% Lambda canary deployment A W S C O D E D E P L O Y

Slide 71

Slide 71 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS CodeDeploy safe deployments A W S S A M T E M P L A T E HelloFunction: Type: 'AWS::Serverless::Function’ Properties: Handler: handler.hello Runtime: nodejs12.x CodeUri: ./hello AutoPublishAlias: live DeploymentPreference: Type: Linear10PercentEvery10Minutes Alarms: - !Ref AliasErrorMetricGreaterThanZeroAlarm - !Ref LatestVersionErrorMetricGreaterThanZeroAlarm Hooks: PreTraffic: !Ref PreTrafficLambdaFunction PostTraffic: !Ref PostTrafficLambdaFunction

Slide 72

Slide 72 text

© 2021, Amazon Web Services, Inc. or its Affiliates. HelloFunction: Type: 'AWS::Serverless::Function’ Properties: Handler: handler.hello Runtime: nodejs12.x CodeUri: ./hello AutoPublishAlias: live DeploymentPreference: Type: Linear10PercentEvery10Minutes Alarms: - !Ref AliasErrorMetricGreaterThanZeroAlarm - !Ref LatestVersionErrorMetricGreaterThanZeroAlarm Hooks: PreTraffic: !Ref PreTrafficLambdaFunction PostTraffic: !Ref PostTrafficLambdaFunction Instructs AWS SAM to publish a new version of the function for each new deployment and to link it to the live alias AWS CodeDeploy safe deployments A W S S A M T E M P L A T E

Slide 73

Slide 73 text

© 2021, Amazon Web Services, Inc. or its Affiliates. HelloFunction: Type: 'AWS::Serverless::Function’ Properties: Handler: handler.hello Runtime: nodejs12.x CodeUri: ./hello AutoPublishAlias: live DeploymentPreference: Type: Linear10PercentEvery10Minutes Alarms: - !Ref AliasErrorMetricGreaterThanZeroAlarm - !Ref LatestVersionErrorMetricGreaterThanZeroAlarm Hooks: PreTraffic: !Ref PreTrafficLambdaFunction PostTraffic: !Ref PostTrafficLambdaFunction Canary10Percent30Minutes Canary10Percent5Minutes Canary10Percent10Minutes Canary10Percent15Minutes Linear10PercentEvery10Minutes Linear10PercentEvery1Minute Linear10PercentEvery2Minutes Linear10PercentEvery3Minutes AllAtOnce AWS CodeDeploy safe deployments A W S S A M T E M P L A T E

Slide 74

Slide 74 text

© 2021, Amazon Web Services, Inc. or its Affiliates. HelloFunction: Type: 'AWS::Serverless::Function’ Properties: Handler: handler.hello Runtime: nodejs12.x CodeUri: ./hello AutoPublishAlias: live DeploymentPreference: Type: Linear10PercentEvery10Minutes Alarms: - !Ref AliasErrorMetricGreaterThanZeroAlarm - !Ref LatestVersionErrorMetricGreaterThanZeroAlarm Hooks: PreTraffic: !Ref PreTrafficLambdaFunction PostTraffic: !Ref PostTrafficLambdaFunction A list of alarms that you want to monitor; you can specify a maximum of 10 alarms AWS CodeDeploy safe deployments A W S S A M T E M P L A T E

Slide 75

Slide 75 text

© 2021, Amazon Web Services, Inc. or its Affiliates. HelloFunction: Type: 'AWS::Serverless::Function’ Properties: Handler: handler.hello Runtime: nodejs12.x CodeUri: ./hello AutoPublishAlias: live DeploymentPreference: Type: Linear10PercentEvery10Minutes Alarms: - !Ref AliasErrorMetricGreaterThanZeroAlarm - !Ref LatestVersionErrorMetricGreaterThanZeroAlarm Hooks: PreTraffic: !Ref PreTrafficLambdaFunction PostTraffic: !Ref PostTrafficLambdaFunction Validation Lambda functions that run before and after traffic shifting AWS CodeDeploy safe deployments A W S S A M T E M P L A T E

Slide 76

Slide 76 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Safe deployment demo

Slide 77

Slide 77 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Different strategies for different stages DEV STAGE PROD Linear10PercentEvery10Minutes AWS Lambda function

Slide 78

Slide 78 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Different strategies for different stages Parameters: MyEnvironment: Type: String Default: dev AllowedValues: - dev - staging - prod Conditions: IsProd: !Equals [!Ref MyEnvironment, prod] MySafeDeployedFunction: Type: "AWS::Serverless::Function" Properties: Handler: mySafeDeployedFunction.handler AutoPublishAlias: live DeploymentPreference: Type: !If [IsProd, Linear10PercentEvery1Minute, AllAtOnce]

Slide 79

Slide 79 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Different strategies for different stages Parameters: MyEnvironment: Type: String Default: dev AllowedValues: - dev - staging - prod Conditions: IsProd: !Equals [!Ref MyEnvironment, prod] MySafeDeployedFunction: Type: "AWS::Serverless::Function" Properties: Handler: mySafeDeployedFunction.handler AutoPublishAlias: live DeploymentPreference: Type: !If [IsProd, Linear10PercentEvery1Minute, AllAtOnce]

Slide 80

Slide 80 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Different strategies for different stages Parameters: MyEnvironment: Type: String Default: dev AllowedValues: - dev - staging - prod Conditions: IsProd: !Equals [!Ref MyEnvironment, prod] MySafeDeployedFunction: Type: "AWS::Serverless::Function" Properties: Handler: mySafeDeployedFunction.handler AutoPublishAlias: live DeploymentPreference: Type: !If [IsProd, Linear10PercentEvery1Minute, AllAtOnce]

Slide 81

Slide 81 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Release process stages Source Build Test Production

Slide 82

Slide 82 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Monitoring and observability Amazon CloudWatch Collects monitoring and operational data in the form of logs, metrics, and events AWS X-Ray Provides a trace or an end-to-end view of requests traveling through your application

Slide 83

Slide 83 text

© 2021, Amazon Web Services, Inc. or its Affiliates. AWS Developer Tools for modern software delivery MONITOR DEPLOY TEST BUILD SOURCE / ARTIFACT AUTHOR AWS Cloud9 AWS IDE Toolkits AWS X-Ray AWS CodeBuild AWS CodeCommit AWS CodeDeploy AWS CodeBuild + Third Party Amazon CloudWatch AWS CodePipeline MODEL AWS CloudFormation AWS SAM AWS Cloud Development Kit AWS CodeArtifact NEW

Slide 84

Slide 84 text

© 2021, Amazon Web Services, Inc. or its Affiliates. “Create application” experience Create a serverless application from a starter template • AWS SAM template for infrastructure as code • CI / CD pipeline • Clone locally for development with AWS SAM CLI

Slide 85

Slide 85 text

© 2021, Amazon Web Services, Inc. or its Affiliates. Thank you! Gunnar Grosch Senior Developer Advocate, AWS @gunnargrosch