- Notifications
You must be signed in to change notification settings - Fork81
Canary deployments for your Serverless application
License
davidgf/serverless-plugin-canary-deployments
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A Serverless plugin to implement canary deployments of Lambda functions, making use of thetraffic shifting feature in combination withAWS CodeDeploy
npm i --save-dev serverless-plugin-canary-deployments
To enable gradual deployments for Lambda functions, yourserverless.yml should look like this:
service:canary-deploymentsprovider:name:awsruntime:nodejs6.10iamRoleStatements: -Effect:AllowAction: -codedeploy:*Resource: -"*"plugins: -serverless-plugin-canary-deploymentsfunctions:hello:handler:handler.helloevents: -http:GET hellodeploymentSettings:type:Linear10PercentEvery1Minutealias:LivepreTrafficHook:preHookpostTrafficHook:postHookalarms: -FooAlarm# When a string is provided, it expects the alarm Logical ID -name:BarAlarm# When an object is provided, it expects the alarm name in the name propertypreHook:handler:hooks.prepostHook:handler:hooks.post
You can see a working example in theexample folder.
type: (required) defines how the traffic will be shifted between Lambda function versions. It must be one of the following:Canary10Percent5Minutes: shifts 10 percent of traffic in the first increment. The remaining 90 percent is deployed five minutes later.Canary10Percent10Minutes: shifts 10 percent of traffic in the first increment. The remaining 90 percent is deployed 10 minutes later.Canary10Percent15Minutes: shifts 10 percent of traffic in the first increment. The remaining 90 percent is deployed 15 minutes later.Canary10Percent30Minutes: shifts 10 percent of traffic in the first increment. The remaining 90 percent is deployed 30 minutes later.Linear10PercentEvery1Minute: shifts 10 percent of traffic every minute until all traffic is shifted.Linear10PercentEvery2Minutes: shifts 10 percent of traffic every two minutes until all traffic is shifted.Linear10PercentEvery3Minutes: shifts 10 percent of traffic every three minutes until all traffic is shifted.Linear10PercentEvery10Minutes: shifts 10 percent of traffic every 10 minutes until all traffic is shifted.AllAtOnce: shifts all the traffic to the new version, useful when you only need to execute the validation hooks.
alias: (required) name that will be used to create the Lambda function alias.preTrafficHook: (optional) validation Lambda function that runs before traffic shifting. It must use the CodeDeploy SDK to notify about this step's success or failure (more infohere).postTrafficHook: (optional) validation Lambda function that runs after traffic shifting. It must use the CodeDeploy SDK to notify about this step's success or failure (more infohere)alarms: (optional) list of CloudWatch alarms. If any of them is triggered during the deployment, the associated Lambda function will automatically roll back to the previous version.triggerConfigurations: (optional) list of CodeDeploy Triggers. See more details in theCodeDeploy TriggerConfiguration Documentation, orthis CodeDeploy notifications guide for example uses
You can set default values for all functions in a top-level custom deploymentSettings section. E.g.:
custom:deploymentSettings:codeDeployRole:some_arn_valuecodeDeployRolePermissionsBoundary:some_arn_valuestages: -dev -prodfunctions:...
Some values are only available as top-level configurations. They are:
codeDeployRole: (optional) an ARN specifying an existing IAM role for CodeDeploy. If absent, one will be created for you. See thecodeDeploy policy for an example of what is needed.codeDeployRolePermissionsBoundary: (optional) an ARN specifying an existing IAM permissions boundary, this permission boundary is set on the code deploy that is being created when codeDeployRole is not defined.stages: (optional) list of stages where you want to deploy your functions gradually. If not present, it assumes that are all of them.
The plugin relies on theAWS Lambda traffic shifting feature to balance traffic between versions andAWS CodeDeploy to automatically update its weight. It modifies theCloudFormation template generated byServerless, so that:
- It creates a Lambda function Alias for each function with deployment settings.
- It creates a CodeDeploy Application and adds aCodeDeploy DeploymentGroup per Lambda function, according to the specified settings.
- It modifies events that trigger Lambda functions, so that they invoke the newly created alias.
For now, the plugin only works with Lambda functions invoked by
- API Gateway
- Stream based (such as the triggered by Kinesis, DynamoDB Streams or SQS)
- SNS based events
- S3 events
- CloudWatch Scheduled events
- CloudWatch Logs
- IoT rules
- AppSync DataSources
More events will be added soon.
ISC ©David García
About
Canary deployments for your Serverless application
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.