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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 85.2MB
glibcpy 3.10–3.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.fixFor 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'.fixAlways 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.fixManually 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.