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 · 35MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 4.5s · import 0.000s · 35MB
34MB installed
● package 34MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Topic
✓ from aws_cdk import aws_sns
✗ from aws_cdk_aws_sns import Topic
AWS CDK v1 constructs are imported from the `aws_cdk` namespace, not directly from the package name `aws_cdk_aws_sns`.
Topic
✓ from aws_cdk import aws_sns
✗ from aws_cdk.aws_sns import Topic
This import path is correct for AWS CDK v2 (where constructs are part of `aws-cdk-lib`), but not for this specific AWS CDK v1 package.
This quickstart demonstrates creating a basic AWS SNS Topic using `aws-cdk-aws-sns` within an AWS CDK v1 application. Save this as `app.py`, then run `cdk synth` from your terminal after installing the required packages (`aws-cdk.core` and `aws-cdk.aws-sns`) and setting up your AWS environment.
import os
from aws_cdk import core as cdk
from aws_cdk import aws_sns as sns
class MySnsStack(cdk.Stack):
def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
# Create an SNS Topic
topic = sns.Topic(self, "MyCdkSnsTopic",
display_name="My First CDK SNS Topic"
)
cdk.CfnOutput(self, "TopicName", value=topic.topic_name)
cdk.CfnOutput(self, "TopicArn", value=topic.topic_arn)
app = cdk.App()
# Ensure AWS account and region are set via env vars or AWS CLI config for cdk synth/deploy
# Example: MySnsStack(app, "MySnsStack", env=cdk.Environment(account=os.environ.get('CDK_DEFAULT_ACCOUNT'), region=os.environ.get('CDK_DEFAULT_REGION')))
MySnsStack(app, "MySnsStack")
app.synth()
Debug
Known issues
breakingThis `aws-cdk-aws-sns` package is specifically for AWS CDK v1. AWS CDK v2 consolidated all constructs into a single `aws-cdk-lib` package and uses different import paths and sometimes different construct properties. Mixing v1 and v2 packages or import styles will lead to errors.fixFor new projects, use `pip install aws-cdk-lib` and update imports to `from aws_cdk import aws_sns` etc. If maintaining a v1 project, ensure all CDK packages are pinned to v1 versions and use `from aws_cdk import aws_sns`.
affects: All versions of `aws-cdk-aws-sns` (which are v1)
gotchaAWS CDK requires the AWS CLI to be installed and configured with credentials for synthesizing and deploying stacks. Your AWS account and region must also be 'bootstrapped' for CDK.fixInstall AWS CLI (`pip install awscli` or system package manager). Configure it (`aws configure`). Run `cdk bootstrap aws://ACCOUNT_ID/REGION` in your target environment.
affects: All versions
gotchaChanging the logical ID (the `construct_id` in `super().__init__(scope, construct_id, ...)` or the second argument in `sns.Topic(self, 'MyTopic', ...)`) of a construct after initial deployment will cause CloudFormation to replace the resource, leading to potential data loss or downtime.fixChoose stable, descriptive logical IDs from the start. If a change is necessary, plan for resource replacement, backups, and potential downtime, or manually migrate resources outside of CDK.
affects: All versions
gotchaCDK applications can generate large CloudFormation templates, especially with many resources or complex patterns. This can hit CloudFormation template size limits (50KB or 200 parameters/resources).fixBreak down large applications into smaller, interconnected CDK stacks (e.g., using cross-stack references) or consider using nested stacks for reusable components.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'aws_cdk_lib'
You are trying to import AWS CDK v2 modules (`aws_cdk_lib`) but have AWS CDK v1 packages (like `aws-cdk-aws-sns`) installed, or vice-versa.
fixDecide whether to use AWS CDK v1 or v2. If v2, uninstall v1 packages and install `aws-cdk-lib`. If v1, ensure all CDK related packages are v1 and imports match `from aws_cdk import ...`.
jsii.errors.JavaScriptError: Error: Stack 'MySnsStack' is not bootstrapped. Please run 'cdk bootstrap' in the account/region.
The AWS environment (account and region) where you are trying to deploy has not been prepared for AWS CDK deployments. CDK needs to provision a few resources (e.g., S3 bucket, IAM roles) to manage deployments.
fixRun `cdk bootstrap aws://YOUR_ACCOUNT_ID/YOUR_REGION` from your terminal, replacing with your actual AWS account ID and desired region.
AttributeError: module 'aws_cdk' has no attribute 'aws_sns'
The `aws-cdk.aws-sns` package is either not installed, or there's a version mismatch between `aws-cdk.core` and `aws-cdk.aws-sns`, or you're attempting a v1 import with a v2 setup.
fixEnsure both `aws-cdk.core` and `aws-cdk.aws-sns` are installed and their versions are compatible (ideally the same v1 version, e.g., `pip install aws-cdk.core==1.204.0 aws-cdk.aws-sns==1.204.0`). Verify your imports are `from aws_cdk import aws_sns`.
Upgrade
Version history
1.204.0latest on PyPI · released Jun 19, 2023
Audit
Dependencies
aws-cdk.corerequiredEssential for any AWS CDK v1 application; provides core classes like App, Stack, and Construct.