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.
from cdk.ecs_codedeploy import TargetService
# 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:
from cdk.ecs_codedeploy import TargetService
# 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:
from cdk.ecs_codedeploy import TargetService
# 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'.
from cdk.ecs_codedeploy import ApiTestStep
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.
from aws_cdk.aws_ecs_patterns import ApplicationLoadBalancedTaskImageOptions
from cdk.ecs_codedeploy import ApiTestStep
# 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.
Release files for cdklabs.ecs-codedeploy 0.0.457
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cdklabs_ecs_codedeploy-0.0.457.tar.gz | 1.1 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cdklabs_ecs_codedeploy-0.0.457-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.3 MB
Release files / cdklabs_ecs_codedeploy-0.0.457.tar.gz
| Download URL | cdklabs_ecs_codedeploy-0.0.457.tar.gz |
|---|---|
| Size | 1.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5d8f47d34922e30fcb5558672dd39f4c320b48046255697d7dae2e5aec68b467
|
|
BLAKE2b-256 checksum How to use checksums |
c16fdf94429ec6bdf42159d27dd3516acb1ae1e6285283c3ea881045671260f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.14.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.
Transparency logRelease files / cdklabs_ecs_codedeploy-0.0.457-py3-none-any.whl
| Download URL | cdklabs_ecs_codedeploy-0.0.457-py3-none-any.whl |
|---|---|
| Size | 1.1 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b861a1e0f2f1809041bab3962869c7f54d22818a8ec232c0145882f99350d63f
|
|
BLAKE2b-256 checksum How to use checksums |
0b3130038392d41c3a26385586a0ae3f3f56acf6897533d61e118405fd6312d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.14.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.
Transparency log