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.99.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6197f805e667d037750ce7d36048e30dcaab7f7c6edf0eb3b323e528a0c17ec |
|
MD5 | 00c6eddcfc86a5b2315a345ba8fc76c0 |
|
BLAKE2b-256 | 32d643cc31093e5335204bbb8629fe11154ff7ebd2508f020ee399403b503b2c |
Hashes for cdklabs.ecs_codedeploy-0.0.99-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a9cc72bc1096e7e1787fb422b3b04b59c63ea5fc3db378de72fd15fcf863138 |
|
MD5 | b4beae3ead4768ea9193e77c74ed6b9a |
|
BLAKE2b-256 | 2cf32b5f7391bf3af7576b6433867b175291f5e5ba4446aa3f546843653f36b0 |