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.58.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a24c4905fb43d00646d621a9233f7cebafe13ec3d18ad4663a85fe578747b8e3 |
|
MD5 | 3f562930471c7fee4425e72689a739a5 |
|
BLAKE2b-256 | 674cf4c7ae91b99088d0fdc9866b29542795b1dc87976c7d73d33c960940b8a4 |
Hashes for cdklabs.ecs_codedeploy-0.0.58-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d793ce1ba916263e51fa5a802378239f42f349817d0fdd76284f8f7ff2eb9bcf |
|
MD5 | 6cc97227244a923e81a51e3d5af93958 |
|
BLAKE2b-256 | c3697f5e3b7c7471879236b920e34ef61ee4dc161c189c9752d7c5f6d36d0909 |