48
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Randall Hunt, Developer Evangelist at AWS October 24, 2016 Managing the Continuous Delivery of Code to AWS Lambda

Managing the Continuous Delivery of Code to AWS Lambda

Embed Size (px)

Citation preview

Page 1: Managing the Continuous Delivery of Code to AWS Lambda

© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Randall Hunt, Developer Evangelist at AWS

October 24, 2016

Managing the Continuous

Delivery of Code to AWS

Lambda

Page 2: Managing the Continuous Delivery of Code to AWS Lambda
Page 3: Managing the Continuous Delivery of Code to AWS Lambda

Agenda

CD Overview

Key Services and Features

Things to be Aware Of

Tips & Tricks

What’s Next?

Page 4: Managing the Continuous Delivery of Code to AWS Lambda

Continuous Delivery Overview

Page 5: Managing the Continuous Delivery of Code to AWS Lambda

Continuous Delivery Overview

Source Build Test Production

Continuous integration

Continuous delivery

Continuous deployment

Page 6: Managing the Continuous Delivery of Code to AWS Lambda

Continuous Delivery Benefits

Improve developer

productivity

Find and address

bugs quickly

Deliver updates fasterAutomate the software

release process

Page 7: Managing the Continuous Delivery of Code to AWS Lambda

Scope of this Webinar

Page 8: Managing the Continuous Delivery of Code to AWS Lambda

Continuous Delivery Overview

Source Build Test Production

Continuous integration

Continuous delivery

Continuous deployment

Page 9: Managing the Continuous Delivery of Code to AWS Lambda

Our Application – A Serverless Website

AWS Lambda

Functions

web browser

Amazon S3

Dynamic Content

Amazon API

Gateway

Amazon

DynamoDB

Overview of building this application:

http://bit.ly/1MJb0O2

Static Content

Page 10: Managing the Continuous Delivery of Code to AWS Lambda

Our Role

AWS Lambda

Functions

web browser

Amazon S3

Dynamic Content

Amazon API

Gateway

Amazon

DynamoDB

Static Content

Page 11: Managing the Continuous Delivery of Code to AWS Lambda

Our Goal

Continuous Delivery pipeline to automate deployment and

release of new Lambda function code to non-Production

environments.

Page 12: Managing the Continuous Delivery of Code to AWS Lambda

Key Services and Features

Page 13: Managing the Continuous Delivery of Code to AWS Lambda

AWS CodePipeline

Page 14: Managing the Continuous Delivery of Code to AWS Lambda

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 3rd party tools and AWS

AWS CodePipeline

Page 15: Managing the Continuous Delivery of Code to AWS Lambda

AWS CodePipeline Benefits

Improved quality

Rapid delivery Get started fast

Configurable workflow Easy to integrate

Page 16: Managing the Continuous Delivery of Code to AWS Lambda

Source

Source

GitHub

Build

JenkinsOnEC2

Jenkins

Deploy

JavaApp

Elastic Beanstalk

PipelineStageAction

Transition

CodePipeline

MyApplication

Page 17: Managing the Continuous Delivery of Code to AWS Lambda

Source

Source

GitHub

Build

JenkinsOnEC2

Jenkins

Deploy

JavaApp

Elastic Beanstalk

NotifyDevelopers

Lambda

CodePipeline

MyApplication

Parallel actions

Page 18: Managing the Continuous Delivery of Code to AWS Lambda

Source

Source

GitHub

Build

JenkinsOnEC2

Jenkins

Deploy

JavaApp

Elastic Beanstalk

NotifyDevelopers

Lambda

TestAPI

Runscope

CodePipeline

MyApplication

Sequential actions

Page 19: Managing the Continuous Delivery of Code to AWS Lambda

AWS service integrations

Source Invoke Logic Deploy

AWS Elastic Beanstalk AWS CodeCommit

Amazon S3 AWS CodeDeploy

AWS Lambda

Page 20: Managing the Continuous Delivery of Code to AWS Lambda

We have a strong partner list, and it’s growing

Source Build Test Deploy

Page 21: Managing the Continuous Delivery of Code to AWS Lambda

Extend AWS CodePipeline Using Custom Actions

Update tickets Provision resources

Update dashboards Send notifications Security scan

Mobile testing

Page 22: Managing the Continuous Delivery of Code to AWS Lambda

2. Perform Job

1. Invoke Lambda function

Source

Source

GitHub

Build

JenkinsOnEC2

Jenkins

Deploy

PublishVersion

AWS Lambda

MyApplicationCodePipeline

AWS

Lambda

3. PutJobSuccessResult

AWS Code Pipeline lets you invoke Lambda functions at each stage.

Page 23: Managing the Continuous Delivery of Code to AWS Lambda

CodePipeline Overview

Job/Stage/Action Metadata

• UserParameters

• Input/Output Artifacts

• Artifact Credentials

{

"CodePipeline.job": {

"id": "8eb1c985-8031-4186-af7e-fdaa049e0a77",

"accountId": "xxx",

"data": {

"actionConfiguration": {

"configuration": {

"FunctionName": "PublishNewLambdaVersion",

"UserParameters": "function=LambdaFunctionName"

}

},

"inputArtifacts": [

{

"location": {

"s3Location": {

"bucketName": "codepipeline-us-east-1-xxx",

"objectKey": "Demo-Pipeline-Test/FunctionSo/M4BQFoQ.zip"

},

"type": "S3"

},

"revision": null,

"name": "FunctionSourceBundleName"

}

],

"outputArtifacts": [

{

"location": {

"s3Location": {

"bucketName": "codepipeline-us-east-1-xxx",

"objectKey": "Demo-Pipeline-Test/TestExecut/vG2GUh3"

},

"type": "S3"

},

"revision": null,

"name": "TestExecutionRequest"

}

],

"artifactCredentials": {

"secretAccessKey": "xxx",

"sessionToken": "xxx",

"accessKeyId": "xxx"

}

}

}

}

Page 24: Managing the Continuous Delivery of Code to AWS Lambda

Our Pipeline

• Built code package lands in S3.

• Lambda Functions all the way down.

• Publish new Function version

• Integration Test

• Release function to environment

• Rollback if necessary

Page 25: Managing the Continuous Delivery of Code to AWS Lambda

Creating a Pipeline via the CLI

{

"roleArn": "IAM-ROLE-ARN-FOR-

CODEPIPELINE-SERVICE",

"stages": [

{

"name": "Source",

"actions": [

{

"inputArtifacts":

[],

"name": "Source",

"actionTypeId": {

"category":

"Source",

"owner": "AWS",

"version": "1",

"provider": "S3"

},

"outputArtifacts": [

{

"name":

"FunctionSourceBundleName"

}

],

"configuration": {

"S3Bucket":

"SRC-BUCKET",

"S3ObjectKey":

"SRC-KEY.zip"

},

"runOrder": 1

}

]

},

{

"name": "dev",

"actions": [

{

"inputArtifacts": [

{

"name":

"FunctionSourceBundleName"

}

],

"name": "Publish-

Dev-Version",

"actionTypeId": {

"category":

"Invoke",

"owner": "AWS",

"version": "1",

"provider":

"Lambda"

},

"outputArtifacts": [

{

"name":

"TestExecutionRequest"

}

],

"configuration": {

"FunctionName":

"PublishNewLambdaVersion",

"UserParameters":

"function=LambdaFunctionNameToPublish"

},

"runOrder": 1

}

]

}

],

"artifactStore": {

"type": "S3",

"location": "BUCKET-NAME-THAT-

MEETS-CODEPIPELINE-REQUIREMENTS"

},

"name": "YOUR-PIPELINE-NAME"

}

aws codepieline create-pipeline --pipeline file://the-below.json

Page 26: Managing the Continuous Delivery of Code to AWS Lambda

AWS Lambda

Page 27: Managing the Continuous Delivery of Code to AWS Lambda

AWS Lambda –

CD Relevant Features

Page 28: Managing the Continuous Delivery of Code to AWS Lambda

Function Versions

• Version your functions

• “Deployment” history

• Export code

• Can be used in parallel to each other

• Code as Infrastructure

Page 29: Managing the Continuous Delivery of Code to AWS Lambda

http://docs.aws.amazon.com/lambda/latest/dg/API_UpdateFunctionCode.html

Page 30: Managing the Continuous Delivery of Code to AWS Lambda

Function Aliases

• Assigned to function versions

• Can be reassigned

• Decouple clients from versioning

• Think of changing an alias as the

“Release” step, can enable Blue-Green

deployments.

Page 31: Managing the Continuous Delivery of Code to AWS Lambda

Amazon API Gateway

Page 32: Managing the Continuous Delivery of Code to AWS Lambda

Amazon API Gateway –

CD Relevant Features

Page 33: Managing the Continuous Delivery of Code to AWS Lambda

API Stages

Page 34: Managing the Continuous Delivery of Code to AWS Lambda

Stage Variables

Combine API Stages with Lambda Function Aliases

Page 35: Managing the Continuous Delivery of Code to AWS Lambda

API Gateway Swagger Import/Export APIs

Page 36: Managing the Continuous Delivery of Code to AWS Lambda

Live Demo

Page 37: Managing the Continuous Delivery of Code to AWS Lambda

Live Demo – Our Pipeline

Amazon

DynamoDB

AddItem

PublishNewVersion

TestNewVersion

ReleaseAndValidate

Amazon API

Gateway

AddItem-Test

AddItem-ApiTest

Page 38: Managing the Continuous Delivery of Code to AWS Lambda

Things to be Aware of

Page 39: Managing the Continuous Delivery of Code to AWS Lambda

Things to be Aware of

AWS Lambda

• Different aliases assigned

to same version share

containers. Function code

should be alias-aware.

• New version means new

containers, remember to

pre-warm if needed.

• Lambda source code must

change for new version to

be published.

Amazon API Gateway

• Stage variable changes do

NOT require an API

deployment. Saving a

stage variable change

takes effect immediately.

AWS CodePipeline

• Job will hang until timeout, unless your Actions make the proper Success/Failure API call.

• Transitions between stages are Enabled OR Disabled. No concept today of manually permitting one job to proceed.

• Many capabilities via CLI/API not yet visible in the console.

Page 40: Managing the Continuous Delivery of Code to AWS Lambda

Tips & Tricks

Page 41: Managing the Continuous Delivery of Code to AWS Lambda

Tips & Tricks

CodePipeline Success/Failure Callback

Implement failure first - Think “Test Driven Development”

Fan-out testing – have a single Lambda “test suite” function that

invokes several test-case functions.

Continuation Tokens – use to extend Lambda-based actions

beyond 5 minutes.

API Versioning – don’t couple your Lambda function versions to

API versions (i.e. api.example.com/v1/prod). Would be disruptive

to your clients and discourage rapid Lambda function changes.

Page 42: Managing the Continuous Delivery of Code to AWS Lambda

Tips & Tricks Contd.

Baby Steps toward CD – Use scheduled Lambda function to

enable/disable stage transition nightly.

Surround with CloudFormation

AWS CodePipline + AWS Lambda + Amazon API Gateway are all

supported now!

Don’t rely on $LATEST for Lambda functions in a testing/production

environment – take control of testing/blessing versions and aliases.

Page 43: Managing the Continuous Delivery of Code to AWS Lambda

Great Lambda Frameworks

• Chalice

• Zappa

• Express

Page 44: Managing the Continuous Delivery of Code to AWS Lambda

What’s next?

Page 45: Managing the Continuous Delivery of Code to AWS Lambda

Expand your CI/CD Scope!

CodeCommit Integration

Static Code Analysis (FindBugs, JSHint, Pylint)

Automated Build – (Jenkins, Solano CI, or your own!)

CloudWatch Events – Success/Failure Detection & Action

Page 46: Managing the Continuous Delivery of Code to AWS Lambda

© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

All attendees will receive a special giveaway gift!

Please join us for the

AWS DevDay Networking Reception

5:00 - 6:30 PM

JW Grand Foyer

Page 47: Managing the Continuous Delivery of Code to AWS Lambda

Thank You!

Page 48: Managing the Continuous Delivery of Code to AWS Lambda

We’re Hiring!

Email us at

[email protected]