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.
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.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cdklabs_ecs_codedeploy-0.0.427.tar.gz.
File metadata
- Download URL: cdklabs_ecs_codedeploy-0.0.427.tar.gz
- Upload date:
- Size: 1.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c48ae25f86643096216dc4ea9d2c033e1b676dafd15f6ec387d767077210fbc6
|
|
| MD5 |
18154cf4813301ba5a47285f494986f5
|
|
| BLAKE2b-256 |
7c1630e59acbafb8cf95eb2719e637933f73b6e325eeed688c3ce65429d31529
|
Provenance
The following attestation bundles were made for cdklabs_ecs_codedeploy-0.0.427.tar.gz:
Publisher:
release.yml on cdklabs/cdk-ecs-codedeploy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cdklabs_ecs_codedeploy-0.0.427.tar.gz -
Subject digest:
c48ae25f86643096216dc4ea9d2c033e1b676dafd15f6ec387d767077210fbc6 - Sigstore transparency entry: 931871576
- Sigstore integration time:
-
Permalink:
cdklabs/cdk-ecs-codedeploy@9fd90d7831718aeafda4b22badc4d262c5a9f2e7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/cdklabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9fd90d7831718aeafda4b22badc4d262c5a9f2e7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cdklabs_ecs_codedeploy-0.0.427-py3-none-any.whl.
File metadata
- Download URL: cdklabs_ecs_codedeploy-0.0.427-py3-none-any.whl
- Upload date:
- Size: 1.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa462aead403a2fbad9346bc8b3c036ca25f253e32369a848db7408f8e617515
|
|
| MD5 |
e178c8d752d5fb65b95d8031ec122f64
|
|
| BLAKE2b-256 |
a8e1cd83a718c7985fe546b90e26509fc0ba256cc0e7eacdd8edfbfc2f1f449f
|
Provenance
The following attestation bundles were made for cdklabs_ecs_codedeploy-0.0.427-py3-none-any.whl:
Publisher:
release.yml on cdklabs/cdk-ecs-codedeploy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cdklabs_ecs_codedeploy-0.0.427-py3-none-any.whl -
Subject digest:
aa462aead403a2fbad9346bc8b3c036ca25f253e32369a848db7408f8e617515 - Sigstore transparency entry: 931871530
- Sigstore integration time:
-
Permalink:
cdklabs/cdk-ecs-codedeploy@9fd90d7831718aeafda4b22badc4d262c5a9f2e7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/cdklabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9fd90d7831718aeafda4b22badc4d262c5a9f2e7 -
Trigger Event:
push
-
Statement type: