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.
# deployment_group: codeDeploy.IEcsDeploymentGroup
# task_definition: ecs.ITaskDefinition
EcsDeployment(
deployment_group=deployment_group,
target_service=TargetService(
task_definition=task_definition,
container_name="mycontainer",
container_port=80
)
)
The deployment will use the AutoRollbackConfig for the EcsDeploymentGroup unless it is overridden in the deployment:
# deployment_group: codeDeploy.IEcsDeploymentGroup
# task_definition: ecs.ITaskDefinition
EcsDeployment(
deployment_group=deployment_group,
target_service=TargetService(
task_definition=task_definition,
container_name="mycontainer",
container_port=80
),
auto_rollback=codeDeploy.AutoRollbackConfig(
failed_deployment=True,
deployment_in_alarm=True,
stopped_deployment=False
)
)
By default, the deployment will timeout after 30 minutes. The timeout value can be overridden:
# deployment_group: codeDeploy.IEcsDeploymentGroup
# task_definition: ecs.ITaskDefinition
EcsDeployment(
deployment_group=deployment_group,
target_service=TargetService(
task_definition=task_definition,
container_name="mycontainer",
container_port=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'
.
canary = ApiCanary(stack, "Canary",
base_url="https://xkcd.com",
duration_alarm_threshold=Duration.seconds(5),
thread_count=5,
steps=[ApiTestStep(
name="info",
path="/908/info.0.json",
jmes_path="safe_title",
expected_value="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.
# cluster: ecs.ICluster
# image: ecs.ContainerImage
service = ApplicationLoadBalancedCodeDeployedFargateService(stack, "Service",
cluster=cluster,
task_image_options=ApplicationLoadBalancedTaskImageOptions(
image=image
),
api_test_steps=[ApiTestStep(
name="health",
path="/health",
jmes_path="status",
expected_value="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.252.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3353623cd48408cb181dfda692bf2108c365434958e986d76d6ceaf6ec3ca1e |
|
MD5 | 6a367e185a616d56079d5d91c4eedd54 |
|
BLAKE2b-256 | e3a7ee30e0d3ebd9c691b4c866232439adc6c2cd56575f3227ee4b05a52b1b59 |
Hashes for cdklabs.ecs_codedeploy-0.0.252-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 407ff582513102df5042a27c2067298eb470cbd328df34e9c6f45a48598531e1 |
|
MD5 | 54e1d1873fda7a26d73416f8ab78eeda |
|
BLAKE2b-256 | 08479b713b5fc5daaba2a89f6a21af658307723b90c5520b478d7fd1c0c4b0e3 |