# CDK ECS CodeDeploy
[](https://constructs.dev/packages/@cdklabs/cdk-ecs-codedeploy)
[](https://badge.fury.io/js/@cdklabs%2Fcdk-ecs-codedeploy)
[](https://maven-badges.herokuapp.com/maven-central/io.github.cdklabs/cdk-ecs-codedeploy)
[](https://badge.fury.io/py/cdklabs.ecs-codedeploy)
[](https://badge.fury.io/nu/Cdklabs.CdkEcsCodeDeploy)
[](https://gitpod.io/#https://github.com/cdklabs/cdk-ecs-codedeploy)
[](https://mergify.io)
This project contains CDK constructs to create CodeDeploy ECS deployments.
## Installation
<details><summary><strong>TypeScript</strong></summary>
```bash
yarn add @cdklabs/cdk-ecs-codedeploy
```
</details><details><summary><strong>Java</strong></summary>
See https://mvnrepository.com/artifact/io.github.cdklabs/cdk-ecs-codedeploy
</details><details><summary><strong>Python</strong></summary>
See https://pypi.org/project/cdklabs.ecs-codedeploy/
</details><details><summary><strong>C#</strong></summary>
See https://www.nuget.org/packages/Cdklabs.CdkEcsCodeDeploy/
</details>
### 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.
```python
# 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:
```python
# 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:
```python
# 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'`.
```python
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](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs_patterns.ApplicationLoadBalancedFargateService.html) 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.
```python
# 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
```bash
yarn install
yarn build
yarn test
```
To run an integration test and update the snapshot, run:
```bash
yarn integ:ecs-deployment:deploy
```
To recreate snapshots for integration tests, run:
```bash
yarn integ:snapshot-all
```
## Security
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
## License
This project is licensed under the Apache-2.0 License.
Raw data
{
"_id": null,
"home_page": "https://github.com/cdklabs/cdk-ecs-codedeploy",
"name": "cdklabs.ecs-codedeploy",
"maintainer": null,
"docs_url": null,
"requires_python": "~=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Amazon Web Services<aws-cdk-dev@amazon.com>",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/94/56/ee4d732cdf0cad7526bf6bdcc4a49146475ddc2f23b4a283e6af357e0a82/cdklabs_ecs_codedeploy-0.0.378.tar.gz",
"platform": null,
"description": "# CDK ECS CodeDeploy\n\n[](https://constructs.dev/packages/@cdklabs/cdk-ecs-codedeploy)\n[](https://badge.fury.io/js/@cdklabs%2Fcdk-ecs-codedeploy)\n[](https://maven-badges.herokuapp.com/maven-central/io.github.cdklabs/cdk-ecs-codedeploy)\n[](https://badge.fury.io/py/cdklabs.ecs-codedeploy)\n[](https://badge.fury.io/nu/Cdklabs.CdkEcsCodeDeploy)\n[](https://gitpod.io/#https://github.com/cdklabs/cdk-ecs-codedeploy)\n[](https://mergify.io)\n\nThis project contains CDK constructs to create CodeDeploy ECS deployments.\n\n## Installation\n\n<details><summary><strong>TypeScript</strong></summary>\n\n```bash\nyarn add @cdklabs/cdk-ecs-codedeploy\n```\n\n</details><details><summary><strong>Java</strong></summary>\n\nSee https://mvnrepository.com/artifact/io.github.cdklabs/cdk-ecs-codedeploy\n\n</details><details><summary><strong>Python</strong></summary>\n\nSee https://pypi.org/project/cdklabs.ecs-codedeploy/\n\n</details><details><summary><strong>C#</strong></summary>\n\nSee https://www.nuget.org/packages/Cdklabs.CdkEcsCodeDeploy/\n\n</details>\n\n### Deployments\n\nCodeDeploy for ECS can manage the deployment of new task definitions to ECS services. Only 1 deployment construct can be defined for a given EcsDeploymentGroup.\n\n```python\n# deployment_group: codeDeploy.IEcsDeploymentGroup\n# task_definition: ecs.ITaskDefinition\n\n\nEcsDeployment(\n deployment_group=deployment_group,\n target_service=TargetService(\n task_definition=task_definition,\n container_name=\"mycontainer\",\n container_port=80\n )\n)\n```\n\nThe deployment will use the AutoRollbackConfig for the EcsDeploymentGroup unless it is overridden in the deployment:\n\n```python\n# deployment_group: codeDeploy.IEcsDeploymentGroup\n# task_definition: ecs.ITaskDefinition\n\n\nEcsDeployment(\n deployment_group=deployment_group,\n target_service=TargetService(\n task_definition=task_definition,\n container_name=\"mycontainer\",\n container_port=80\n ),\n auto_rollback=codeDeploy.AutoRollbackConfig(\n failed_deployment=True,\n deployment_in_alarm=True,\n stopped_deployment=False\n )\n)\n```\n\nBy default, the deployment will timeout after 30 minutes. The timeout value can be overridden:\n\n```python\n# deployment_group: codeDeploy.IEcsDeploymentGroup\n# task_definition: ecs.ITaskDefinition\n\n\nEcsDeployment(\n deployment_group=deployment_group,\n target_service=TargetService(\n task_definition=task_definition,\n container_name=\"mycontainer\",\n container_port=80\n ),\n timeout=Duration.minutes(60)\n)\n```\n\n### API Canaries\n\nCodeDeploy 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'`.\n\n```python\ncanary = ApiCanary(stack, \"Canary\",\n base_url=\"https://xkcd.com\",\n duration_alarm_threshold=Duration.seconds(5),\n thread_count=5,\n steps=[ApiTestStep(\n name=\"info\",\n path=\"/908/info.0.json\",\n jmes_path=\"safe_title\",\n expected_value=\"The Cloud\"\n )\n ]\n)\n```\n\n### Application Load Balanced CodeDeployed Fargate Service\n\nAn L3 construct named `ApplicationLoadBalancedCodeDeployedFargateService` extends [ApplicationLoadBalancedFargateService](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs_patterns.ApplicationLoadBalancedFargateService.html) 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.\n\n```python\n# cluster: ecs.ICluster\n# image: ecs.ContainerImage\n\nservice = ApplicationLoadBalancedCodeDeployedFargateService(stack, \"Service\",\n cluster=cluster,\n task_image_options=ApplicationLoadBalancedTaskImageOptions(\n image=image\n ),\n api_test_steps=[ApiTestStep(\n name=\"health\",\n path=\"/health\",\n jmes_path=\"status\",\n expected_value=\"ok\"\n )]\n)\n```\n\n## Local Development\n\n```bash\nyarn install\nyarn build\nyarn test\n```\n\nTo run an integration test and update the snapshot, run:\n\n```bash\nyarn integ:ecs-deployment:deploy\n```\n\nTo recreate snapshots for integration tests, run:\n\n```bash\nyarn integ:snapshot-all\n```\n\n## Security\n\nSee [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.\n\n## License\n\nThis project is licensed under the Apache-2.0 License.\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "CDK Constructs for performing ECS Deployments with CodeDeploy",
"version": "0.0.378",
"project_urls": {
"Homepage": "https://github.com/cdklabs/cdk-ecs-codedeploy",
"Source": "https://github.com/cdklabs/cdk-ecs-codedeploy"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "61f9a380824757da5e29b8c2ed03b3d59a0c1d1f189c3fc51f9657762988ac60",
"md5": "60340e5960f4d9536680b6cfc9369657",
"sha256": "d5e28012b33125cfcf8ff002926642c2700b303fa1c85c955c2d4e7aa3aaaf42"
},
"downloads": -1,
"filename": "cdklabs.ecs_codedeploy-0.0.378-py3-none-any.whl",
"has_sig": false,
"md5_digest": "60340e5960f4d9536680b6cfc9369657",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "~=3.8",
"size": 949639,
"upload_time": "2025-02-15T18:16:08",
"upload_time_iso_8601": "2025-02-15T18:16:08.141130Z",
"url": "https://files.pythonhosted.org/packages/61/f9/a380824757da5e29b8c2ed03b3d59a0c1d1f189c3fc51f9657762988ac60/cdklabs.ecs_codedeploy-0.0.378-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "9456ee4d732cdf0cad7526bf6bdcc4a49146475ddc2f23b4a283e6af357e0a82",
"md5": "09a7f4bb3c44eced5908c785164816e2",
"sha256": "9b400e9921012d202be4e946eb3e30a3350da7f2c3b7c8b97636b9d4b508e533"
},
"downloads": -1,
"filename": "cdklabs_ecs_codedeploy-0.0.378.tar.gz",
"has_sig": false,
"md5_digest": "09a7f4bb3c44eced5908c785164816e2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "~=3.8",
"size": 951013,
"upload_time": "2025-02-15T18:16:10",
"upload_time_iso_8601": "2025-02-15T18:16:10.157622Z",
"url": "https://files.pythonhosted.org/packages/94/56/ee4d732cdf0cad7526bf6bdcc4a49146475ddc2f23b4a283e6af357e0a82/cdklabs_ecs_codedeploy-0.0.378.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-15 18:16:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cdklabs",
"github_project": "cdk-ecs-codedeploy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "cdklabs.ecs-codedeploy"
}