{"id":180,"library":"aws-cdk-lib","title":"AWS CDK Library (aws-cdk-lib)","description":"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.","status":"active","version":"2.244.0","language":"python","source_language":"en","source_url":"https://github.com/aws/aws-cdk","tags":["aws-cdk","aws","iac","infrastructure","python","cdk","cloudformation"],"install":[{"cmd":"pip install aws-cdk-lib constructs","lang":"bash","label":"Python (core — both required)"},{"cmd":"npm install -g aws-cdk","lang":"bash","label":"CDK CLI (required separately)"}],"dependencies":[{"reason":"Required. Construct base class moved to separate package in v2. Must install alongside aws-cdk-lib.","package":"constructs","optional":false}],"imports":[{"note":"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.","wrong":"# v1 style — all these packages are EOL\nfrom aws_cdk.core import Stack, App, Construct\nfrom aws_cdk import aws_s3 as s3  # wrong in v1 too\nimport aws_cdk.aws_s3 as s3      # v1 style\nfrom aws_cdk.aws_s3 import Bucket # v1 style","symbol":"v2 import pattern","correct":"import aws_cdk as cdk\nfrom aws_cdk import (\n    Stack,\n    App,\n    Duration,\n    RemovalPolicy,\n    aws_s3 as s3,\n    aws_lambda as lambda_,\n    aws_iam as iam,\n)\nfrom constructs import Construct\n\nclass MyStack(Stack):\n    def __init__(self, scope: Construct, id: str, **kwargs):\n        super().__init__(scope, id, **kwargs)\n\n        bucket = s3.Bucket(\n            self, 'MyBucket',\n            removal_policy=RemovalPolicy.DESTROY,\n            versioned=True\n        )\n\napp = App()\nMyStack(app, 'MyStack')\napp.synth()"},{"note":"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.","wrong":"# Wrong: trying to import experimental constructs from aws_cdk directly\nfrom aws_cdk import aws_apigatewayv2  # may not exist or be incomplete","symbol":"experimental alpha packages","correct":"# Stable constructs — from aws_cdk\nfrom aws_cdk import aws_s3 as s3\nfrom aws_cdk import aws_lambda as lambda_\n\n# Experimental constructs — separate alpha package\n# pip install aws-cdk.aws-apigatewayv2-alpha\nfrom aws_cdk.aws_apigatewayv2_alpha import HttpApi\n\n# Check stability before using — alpha APIs may break between minor versions"}],"quickstart":{"code":"# pip install aws-cdk-lib constructs\n# npm install -g aws-cdk\n# cdk bootstrap aws://ACCOUNT-ID/REGION\n\nimport aws_cdk as cdk\nfrom aws_cdk import (\n    Stack,\n    aws_s3 as s3,\n    aws_lambda as lambda_,\n    aws_iam as iam,\n    Duration,\n    RemovalPolicy,\n    CfnOutput,\n)\nfrom constructs import Construct\n\nclass MyAppStack(Stack):\n    def __init__(self, scope: Construct, id: str, **kwargs):\n        super().__init__(scope, id, **kwargs)\n\n        # S3 bucket\n        bucket = s3.Bucket(\n            self, 'MyBucket',\n            versioned=True,\n            removal_policy=RemovalPolicy.DESTROY,\n            auto_delete_objects=True\n        )\n\n        # Lambda function\n        fn = lambda_.Function(\n            self, 'MyFunction',\n            runtime=lambda_.Runtime.PYTHON_3_12,\n            handler='index.handler',\n            code=lambda_.Code.from_inline('def handler(e, c): return {\"statusCode\": 200}'),\n            timeout=Duration.seconds(30)\n        )\n\n        # Grant bucket read to lambda\n        bucket.grant_read(fn)\n\n        # Stack output\n        CfnOutput(self, 'BucketName', value=bucket.bucket_name)\n\napp = cdk.App()\nMyAppStack(app, 'MyAppStack', env=cdk.Environment(\n    account='123456789012',\n    region='us-east-1'\n))\napp.synth()\n\n# Deploy: cdk deploy","lang":"python","description":"AWS CDK v2 Python — S3 bucket + Lambda with IAM grant."},"warnings":[{"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.","message":"CDK 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.","severity":"breaking","affected_versions":">= 2.0"},{"fix":"from constructs import Construct — must install 'constructs' package separately.","message":"Construct class moved from aws_cdk.core to the separate 'constructs' package. 'from aws_cdk.core import Construct' raises ImportError in v2.","severity":"breaking","affected_versions":">= 2.0"},{"fix":"Run: cdk bootstrap aws://ACCOUNT-ID/REGION for each account/region combination.","message":"CDK v2 requires re-bootstrapping existing AWS accounts. v1 bootstrap resources are incompatible with v2 synthesizer. Error: 'This CDK deployment requires bootstrap stack version X'.","severity":"breaking","affected_versions":">= 2.0"},{"fix":"npm install -g aws-cdk. Then: cdk init, cdk synth, cdk deploy.","message":"cdk 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.","severity":"breaking","affected_versions":"all"},{"fix":"Pin alpha packages to same version: pip install 'aws-cdk-lib==2.100.0' 'aws-cdk.aws-apigatewayv2-alpha==2.100.0a0'","message":"Experimental constructs (alpha packages like aws-cdk.aws-apigatewayv2-alpha) must match aws-cdk-lib version. Mismatched versions cause dependency conflicts.","severity":"gotcha","affected_versions":"all"},{"fix":"Update CDK CLI: npm install -g aws-cdk@latest","message":"Cloud 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'.","severity":"gotcha","affected_versions":"all"},{"fix":"lambda_.Runtime.PYTHON_3_12 or lambda_.Runtime.PYTHON_3_13","message":"lambda_.Runtime.PYTHON_3_8 deprecated. Python 3.8 Lambda runtime EOL Oct 2024. Use PYTHON_3_12 or PYTHON_3_13.","severity":"gotcha","affected_versions":"all"},{"fix":"s3.Bucket(self, 'B', removal_policy=RemovalPolicy.DESTROY, auto_delete_objects=True)","message":"RemovalPolicy.DESTROY on S3 buckets does not delete bucket contents. Bucket must also have auto_delete_objects=True to actually delete on cdk destroy.","severity":"gotcha","affected_versions":"all"},{"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.","message":"AWS 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.","severity":"breaking","affected_versions":"all"},{"fix":"Install Node.js. For Alpine Linux (python:3.13-alpine), use 'apk add nodejs'.","message":"The 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.","severity":"breaking","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T09:46:38.326Z","next_check":"2026-06-25T00:00:00.000Z","problems":[{"fix":"Replace 'from aws_cdk import core' with 'from aws_cdk import App, Stack' and import other constructs directly from 'aws_cdk'.","cause":"In AWS CDK v2, the 'core' module has been replaced by 'aws-cdk-lib'.","error":"ModuleNotFoundError: No module named 'aws_cdk.core'"},{"fix":"Update imports to 'from aws_cdk import App, Stack' and import other constructs directly from 'aws_cdk'.","cause":"The 'core' module was removed in AWS CDK v2; all constructs are now imported from 'aws-cdk-lib'.","error":"ImportError: cannot import name 'core' from 'aws_cdk'"},{"fix":"Replace 'import * as s3 from '@aws-cdk/aws-s3'' with 'import * as s3 from 'aws-cdk-lib/aws-s3''.","cause":"In AWS CDK v2, all service modules are consolidated into 'aws-cdk-lib'.","error":"Cannot find module '@aws-cdk/aws-s3'"},{"fix":"Run 'cdk synth --app 'node bin/my-app.js'' or add the 'app' field in 'cdk.json'.","cause":"The 'cdk synth' command requires the '--app' option to specify the application entry point.","error":"cdk synth: --app is required either in command-line, in cdk.json or in ~/.cdk.json"},{"fix":"Ensure the deployment bucket exists or run 'cdk bootstrap' to create the necessary resources.","cause":"The S3 bucket used for deployment does not exist or has been deleted.","error":"cdk deploy: NoSuchBucket error"}],"ecosystem":"pypi","meta_description":null,"install_score":0,"install_tag":"stale","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}