CDK Constructs for performing ECS Deployments with CodeDeploy
Project description
CDK ECS CodeDeploy
This project contains CDK constructs to create CodeDeploy ECS deployments.
Installation
TypeScript
yarn add @cdklabs/cdk-ecs-codedeploy
Deployments
CodeDeploy for ECS can manage the deployment of new task definitions to ECS services. Only 1 deployment construct can be defined for a given EcsDeploymentGroup.
declare const deploymentGroup: codeDeploy.IEcsDeploymentGroup;
declare const taskDefinition: ecs.ITaskDefinition;
new EcsDeployment({
deploymentGroup,
targetService: {
taskDefinition,
containerName: 'mycontainer',
containerPort: 80,
},
});
The deployment will use the AutoRollbackConfig for the EcsDeploymentGroup unless it is overridden in the deployment:
new EcsDeployment({
deploymentGroup,
targetService: {
taskDefinition,
containerName: 'mycontainer',
containerPort: 80,
},
autoRollback: {
failedDeployment: true,
deploymentInAlarm: true,
stoppedDeployment: false,
},
});
By default, the deployment will timeout after 30 minutes. The timeout value can be overridden:
new EcsDeployment({
deploymentGroup,
targetService: {
taskDefinition,
containerName: 'mycontainer',
containerPort: 80,
},
timeout: Duration.minutes(60),
});
API Canaries
CodeDeploy can leverage Cloudwatch Alarms to trigger automatic rollbacks. The ApiCanary
construct simplifies the process for creating CloudWatch Synthetics Canaries to monitor APIs. The following code demonstrates a canary that monitors https://xkcd.com/908/info.0.json and checks the JSON response to assert that safe_title
has the value of 'The Cloud'
.
const canary = new ApiCanary(stack, 'Canary', {
baseUrl: 'https://xkcd.com',
durationAlarmThreshold: Duration.seconds(5),
threadCount: 5,
steps: [
{
name: 'info',
path: '/908/info.0.json',
jmesPath: 'safe_title',
expectedValue: 'The Cloud',
},
],
});
Application Load Balanced CodeDeployed Fargate Service
An L3 construct named ApplicationLoadBalancedCodeDeployedFargateService
extends ApplicationLoadBalancedFargateService and adds support for deploying new versions of the service with AWS CodeDeploy. Additionally, an Amazon CloudWatch Synthetic canary is created via the ApiCanary
construct and is monitored by the CodeDeploy deployment to trigger rollback if the canary begins to alarm.
declare const cluster: ecs.ICluster;
declare const image: ecs.ContainerImage;
const service = new ApplicationLoadBalancedCodeDeployedFargateService(stack, 'Service', {
cluster,
taskImageOptions: {
image,
},
apiTestSteps: [{
name: 'health',
path: '/health',
jmesPath: 'status',
expectedValue: 'ok',
}],
});
Local Development
yarn install
yarn build
yarn test
To run an integration test and update the snapshot, run:
yarn integ:ecs-deployment:deploy
To recreate snapshots for integration tests, run:
yarn integ:snapshot-all
Security
See CONTRIBUTING for more information.
License
This project is licensed under the Apache-2.0 License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cdklabs.ecs-codedeploy-0.0.55.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31179b8974c64dae339239344dbb351805d084771372180523ce1648ef7be8ef |
|
MD5 | c1caa86f63a87c8308d94c4e06fb7e76 |
|
BLAKE2b-256 | 6e91b5a076d2b96e4162a14e2ffdcd37f3604ce1f43cb1d3a1e6f3d3d8b29dee |
Hashes for cdklabs.ecs_codedeploy-0.0.55-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c31c2ca9c00978f1e5c2bd68dc095fbb6f9dc71feba7e0d0848e0b5882769c9 |
|
MD5 | 2d68b9fd24d3e43c409918bef840a7fd |
|
BLAKE2b-256 | c8609b8dc348b8d7e804c4dcbaeca6774380d467f6eeabddf556a22059b7a7c9 |