Registry / aws / aws-cdk-lib

aws-cdk-lib

JSON →
library2.244.0pypypiunverified

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.

awsdevops
pip install aws-cdk-lib constructs
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
musl
glibc
py 3.10
3/5 runs
3/5 runs
py 3.11
3/5 runs
3/5 runs
py 3.12
3/5 runs
3/5 runs
py 3.13
3/5 runs
3/5 runs
py 3.9
3/5 runs
3/5 runs
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
Debug
Known issues
breakingCDK v1 packages (aws-cdk.core, aws-cdk.aws-s3, etc.) are EOL June 2023. All v1 imports broken in v2. LLMs trained pre-2022 generate v1 import patterns.
fix
Replace all 'from aws_cdk.core import X' with 'from constructs import Construct' and 'from aws_cdk import Stack, App'. Replace 'aws_cdk.aws_s3' with 'aws_cdk.aws_s3' submodule from aws-cdk-lib.
affects: >= 2.0
breakingConstruct class moved from aws_cdk.core to the separate 'constructs' package. 'from aws_cdk.core import Construct' raises ImportError in v2.
fix
from constructs import Construct — must install 'constructs' package separately.
affects: >= 2.0
breakingCDK v2 requires re-bootstrapping existing AWS accounts. v1 bootstrap resources are incompatible with v2 synthesizer. Error: 'This CDK deployment requires bootstrap stack version X'.
fix
Run: cdk bootstrap aws://ACCOUNT-ID/REGION for each account/region combination.
affects: >= 2.0
breakingcdk synth/deploy requires CDK CLI ('npm install -g aws-cdk'). pip install alone gives you no CLI. Running app.py directly with python produces output but doesn't deploy.
fix
npm install -g aws-cdk. Then: cdk init, cdk synth, cdk deploy.
affects: all
gotchaExperimental constructs (alpha packages like aws-cdk.aws-apigatewayv2-alpha) must match aws-cdk-lib version. Mismatched versions cause dependency conflicts.
fix
Pin alpha packages to same version: pip install 'aws-cdk-lib==2.100.0' 'aws-cdk.aws-apigatewayv2-alpha==2.100.0a0'
affects: all
gotchaCloud assembly schema version mismatch error when CDK CLI version is older than aws-cdk-lib version. Error: 'Maximum schema version supported is X.0.0, but found Y.0.0'.
fix
Update CDK CLI: npm install -g aws-cdk@latest
affects: all
gotchalambda_.Runtime.PYTHON_3_8 deprecated. Python 3.8 Lambda runtime EOL Oct 2024. Use PYTHON_3_12 or PYTHON_3_13.
fix
lambda_.Runtime.PYTHON_3_12 or lambda_.Runtime.PYTHON_3_13
affects: all
gotchaRemovalPolicy.DESTROY on S3 buckets does not delete bucket contents. Bucket must also have auto_delete_objects=True to actually delete on cdk destroy.
fix
s3.Bucket(self, 'B', removal_policy=RemovalPolicy.DESTROY, auto_delete_objects=True)
affects: all
breakingAWS CDK Python applications (aws-cdk-lib) rely on the jsii runtime, which requires Node.js to be installed and available in the system's PATH. A 'FileNotFoundError: No such file or directory: 'node'' occurs if Node.js is missing.
fix
Install Node.js (e.g., using a package manager like apt, yum, brew, or nvm) and ensure the 'node' executable is accessible in your system's PATH.
affects: all
breakingThe aws-cdk-lib Python package requires the Node.js runtime to be installed and available in the system's PATH due to its reliance on the jsii runtime. Failure to find 'node' will result in a FileNotFoundError during import.
fix
Install Node.js. For Alpine Linux (python:3.13-alpine), use 'apk add nodejs'.
affects: all
Upgrade
Version history
2.258.1latest on PyPI
Audit
Dependencies
constructsrequiredRequired. Construct base class moved to separate package in v2. Must install alongside aws-cdk-lib.
Agent activity
23 hits · last 30 days
seranking-bot
4
bytedance
3
node
2
Amazon
2
ahrefsbot
2
amazonbot
1
Resources