Registry / aws / aws-cdk-aws-ecs

aws-cdk-aws-ecs

JSON →
library1.204.0pypypiunverified

The `aws-cdk-aws-ecs` package provides AWS Cloud Development Kit (CDK) constructs for defining Amazon Elastic Container Service (ECS) resources in Python. It is part of AWS CDK v1. While functional, AWS CDK v2 is the recommended and actively developed version, which consolidates all constructs into `aws-cdk-lib`. This package is largely superseded by `aws-cdk-lib`'s ECS constructs.

pip install aws-cdk-aws-ecs aws-cdk.core
INSTALL
IMPORT
SIG · AWS-CDK-AWS-ECS
A
aws-cdk-aws-ecs
awspythonv1.204.0
Install
10.3s avg
Import
Disk
90MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.204.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 85.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 10.3s · import 0.000s · 86MB
90MB installed
● package 90MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

aws_ecs
from aws_cdk import aws_ecs
from aws_cdk_lib import aws_ecs
This package is for AWS CDK v1. The `aws_cdk_lib` namespace is for v2.
core
from aws_cdk import core
from aws_cdk_lib import core
AWS CDK v1 core constructs like App and Stack are in `aws_cdk.core`.
aws_ec2
from aws_cdk import aws_ec2
from aws_cdk_lib import aws_ec2
Specific service constructs are imported directly under `aws_cdk` in v1.

This quickstart defines an AWS CDK v1 stack that creates an ECS Fargate cluster and deploys a simple Fargate service with a sample container image. It demonstrates importing `aws_ecs`, `aws_ec2`, and `core` constructs as expected in v1. Ensure `CDK_DEFAULT_ACCOUNT` and `CDK_DEFAULT_REGION` (or `AWS_ACCOUNT_ID`/`AWS_REGION`) environment variables are set.

import os from aws_cdk import ( core, aws_ecs as ecs, aws_ec2 as ec2, aws_ecr as ecr, aws_iam as iam, ) class MyEcsFargateStack(core.Stack): def __init__(self, scope: core.Construct, id: str, **kwargs) -> None: super().__init__(scope, id, **kwargs) # Look up an existing VPC or create a new one vpc = ec2.Vpc(self, "MyVpc", max_azs=2) cluster = ecs.Cluster(self, "MyFargateCluster", vpc=vpc) # Create a Task Definition task_definition = ecs.FargateTaskDefinition( self, "MyTaskDef", memory_limit_mib=512, cpu=256 ) # Add a container to the task definition # Using a public image for simplicity, replace with your ECR image if needed image_name = os.environ.get('ECR_IMAGE_NAME', 'amazon/amazon-ecs-sample') task_definition.add_container( "MyContainer", image=ecs.ContainerImage.from_registry(image_name), port_mappings=[ecs.PortMapping(container_port=80, host_port=80)] ) # Create a Fargate Service ecs.FargateService( self, "MyFargateService", cluster=cluster, task_definition=task_definition, desired_count=1 ) app = core.App() MyEcsFargateStack(app, "MyEcsFargateStack", env=core.Environment( account=os.environ.get("CDK_DEFAULT_ACCOUNT", os.environ.get("AWS_ACCOUNT_ID")), region=os.environ.get("CDK_DEFAULT_REGION", os.environ.get("AWS_REGION")) ) ) app.synth()
Debug
Known issues
breakingAWS CDK v1 (which this package is part of) is largely superseded by AWS CDK v2. V2 consolidates all core constructs into a single package, 'aws-cdk-lib', and has a different module structure. Mixing v1 and v2 packages or attempting to use v1 constructs with a v2 application will lead to errors.
fix
For new projects, use `aws-cdk-lib` and its ECS constructs (e.g., `from aws_cdk import aws_ecs as ecs`). For existing v1 projects, ensure all CDK packages are `aws-cdk.*` and avoid `aws-cdk-lib`. Consider migrating to v2 for long-term support and features.
affects: All v1 versions.
gotchaCDK v1 constructs often require explicit imports for base modules like 'core', 'aws_ec2', 'aws_iam', etc., in addition to the specific 'aws_ecs' module. Forgetting these can lead to 'NameError' or 'AttributeError'.
fix
Always include `from aws_cdk import core` and other required base service modules (e.g., `from aws_cdk import aws_ec2`, `from aws_cdk import aws_iam`) alongside `from aws_cdk import aws_ecs`.
affects: All v1 versions.
gotchaCDK v1 resources, especially during development, might not always clean up fully upon `cdk destroy` if there are dependencies like S3 buckets not explicitly removed or if the stack fails mid-deletion. This can incur unexpected costs.
fix
Manually inspect AWS console for orphaned resources after `cdk destroy` failures. For S3 buckets, ensure `auto_delete_objects=True` and `removal_policy=core.RemovalPolicy.DESTROY` are set if you want them to be deleted with the stack (use with caution in production).
affects: All v1 versions.
Upgrade
Version history
1.204.0latest on PyPI · released Jun 19, 2023
Audit
Dependencies
aws-cdk.corerequiredCore AWS CDK v1 functionality, including App, Stack, and base constructs.
aws-cdk.aws-ec2optionalRequired for network constructs like VPCs, which ECS services often depend on.
aws-cdk.aws-ecroptionalRequired for defining Elastic Container Registry (ECR) repositories or pulling images.
aws-cdk.aws-iamoptionalRequired for defining IAM roles and policies for ECS tasks and services.
Agent activity
22 hits · last 30 days
node
18
OpenAI (training)
2
Resources
aws-cdk-aws-ecs — pip install aws-cdk-aws-ecs · libregistry