Skip to main content

CDK Constructs for performing ECS Deployments with CodeDeploy

Project description

CDK ECS CodeDeploy

cdk-constructs: Experimental npm version Maven Central PyPI version NuGet version Gitpod Ready-to-Code Mergify

This project contains CDK constructs to create CodeDeploy ECS deployments.

Installation

TypeScript
yarn add @cdklabs/cdk-ecs-codedeploy
Java

See https://mvnrepository.com/artifact/io.github.cdklabs/cdk-ecs-codedeploy

Python

See https://pypi.org/project/cdklabs.ecs-codedeploy/

C#

See https://www.nuget.org/packages/Cdklabs.CdkEcsCodeDeploy/

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

cdklabs_ecs_codedeploy-0.0.435.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cdklabs_ecs_codedeploy-0.0.435-py3-none-any.whl (1.3 MB view details)

Uploaded Python 3

File details

Details for the file cdklabs_ecs_codedeploy-0.0.435.tar.gz.

File metadata

  • Download URL: cdklabs_ecs_codedeploy-0.0.435.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.14.3

File hashes

Hashes for cdklabs_ecs_codedeploy-0.0.435.tar.gz
Algorithm Hash digest
SHA256 57db883213f00d7fbe22dca2a852c38e0fd3a0fd6a9ed22b14a5f74d8ca08c67
MD5 c630a2ad9c0831c5ed37affe78c4b536
BLAKE2b-256 1c9085c8817cf0f1203509b92ea51f06de33e1d8555dc863c99ec5ba403fd47b

See more details on using hashes here.

Provenance

The following attestation bundles were made for cdklabs_ecs_codedeploy-0.0.435.tar.gz:

Publisher: release.yml on cdklabs/cdk-ecs-codedeploy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cdklabs_ecs_codedeploy-0.0.435-py3-none-any.whl.

File metadata

File hashes

Hashes for cdklabs_ecs_codedeploy-0.0.435-py3-none-any.whl
Algorithm Hash digest
SHA256 ef64d9d44953a5ee491aa4d7270973fba71d83899217e889a8ce3405a0cdefc9
MD5 71b39318d299378ae85bc2bfff7b23e1
BLAKE2b-256 67852c86fff6a3d0726225f5114ec459681d84a690209d5b43cf7920c8440160

See more details on using hashes here.

Provenance

The following attestation bundles were made for cdklabs_ecs_codedeploy-0.0.435-py3-none-any.whl:

Publisher: release.yml on cdklabs/cdk-ecs-codedeploy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page