AWS Cloud Development Kit v2 — define AWS infrastructure as Python code. Current version: 2.244.0 (Mar 2026). CDK v1 (aws-cdk.core + individual service packages) reached EOL June 2023. v2 consolidates all stable constructs into single 'aws-cdk-lib' package. Import paths completely changed from v1. Construct class moved to separate 'constructs' package. Experimental constructs use '-alpha' suffix packages. Requires CDK CLI ('npm install -g aws-cdk') and 'cdk bootstrap' for each AWS account/region.
Install & Compatibility
Where this runs
tested against v2.258.1 · 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
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
v2 import pattern
✓ import aws_cdk as cdk
from aws_cdk import (
Stack,
App,
Duration,
RemovalPolicy,
aws_s3 as s3,
aws_lambda as lambda_,
aws_iam as iam,
)
from constructs import Construct
class MyStack(Stack):
def __init__(self, scope: Construct, id: str, **kwargs):
super().__init__(scope, id, **kwargs)
bucket = s3.Bucket(
self, 'MyBucket',
removal_policy=RemovalPolicy.DESTROY,
versioned=True
)
app = App()
MyStack(app, 'MyStack')
app.synth()
✗ # v1 style — all these packages are EOL
from aws_cdk.core import Stack, App, Construct
from aws_cdk import aws_s3 as s3 # wrong in v1 too
import aws_cdk.aws_s3 as s3 # v1 style
from aws_cdk.aws_s3 import Bucket # v1 style
v1 used separate packages: aws-cdk.core, aws-cdk.aws-s3, etc. v2 uses single aws-cdk-lib with submodules. Construct class moved from aws_cdk.core to 'constructs' package.
experimental alpha packages
✓ # Stable constructs — from aws_cdk
from aws_cdk import aws_s3 as s3
from aws_cdk import aws_lambda as lambda_
# Experimental constructs — separate alpha package
# pip install aws-cdk.aws-apigatewayv2-alpha
from aws_cdk.aws_apigatewayv2_alpha import HttpApi
# Check stability before using — alpha APIs may break between minor versions
✗ # Wrong: trying to import experimental constructs from aws_cdk directly
from aws_cdk import aws_apigatewayv2 # may not exist or be incomplete
Experimental constructs are in separate '-alpha' packages (e.g. aws-cdk.aws-apigatewayv2-alpha). Alpha APIs can break between minor CDK versions unlike stable aws-cdk-lib.
AWS CDK v2 Python — S3 bucket + Lambda with IAM grant.
# pip install aws-cdk-lib constructs
# npm install -g aws-cdk
# cdk bootstrap aws://ACCOUNT-ID/REGION
import aws_cdk as cdk
from aws_cdk import (
Stack,
aws_s3 as s3,
aws_lambda as lambda_,
aws_iam as iam,
Duration,
RemovalPolicy,
CfnOutput,
)
from constructs import Construct
class MyAppStack(Stack):
def __init__(self, scope: Construct, id: str, **kwargs):
super().__init__(scope, id, **kwargs)
# S3 bucket
bucket = s3.Bucket(
self, 'MyBucket',
versioned=True,
removal_policy=RemovalPolicy.DESTROY,
auto_delete_objects=True
)
# Lambda function
fn = lambda_.Function(
self, 'MyFunction',
runtime=lambda_.Runtime.PYTHON_3_12,
handler='index.handler',
code=lambda_.Code.from_inline('def handler(e, c): return {"statusCode": 200}'),
timeout=Duration.seconds(30)
)
# Grant bucket read to lambda
bucket.grant_read(fn)
# Stack output
CfnOutput(self, 'BucketName', value=bucket.bucket_name)
app = cdk.App()
MyAppStack(app, 'MyAppStack', env=cdk.Environment(
account='123456789012',
region='us-east-1'
))
app.synth()
# Deploy: cdk deploy
cdk --version
Audit
Dependencies
constructsrequiredRequired. Construct base class moved to separate package in v2. Must install alongside aws-cdk-lib.