Registry /
aws / aws-cdk-aws-sns-subscriptions
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.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 55.3MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 12.1s · import 0.000s · 56MB
169MB installed
● package 169MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
SqsSubscription
✓ from aws_cdk.aws_sns_subscriptions import SqsSubscription
✗ from aws_cdk_lib.aws_sns_subscriptions import SqsSubscription
For CDK v1, modules are imported from `aws_cdk.<service>`. For CDK v2, they are consolidated under `aws_cdk.aws_<service>` after installing `aws-cdk-lib`.
LambdaSubscription
✓ from aws_cdk.aws_sns_subscriptions import LambdaSubscription
The import path remains consistent between v1 and v2, but the underlying package changes from `aws-cdk-aws-sns-subscriptions` (v1) to `aws-cdk-lib` (v2).
This quickstart demonstrates how to create an AWS SNS topic and subscribe an SQS queue to it using the `aws-cdk-aws-sns-subscriptions` module. It defines a simple CDK stack, instantiates an SQS queue and an SNS topic, and then uses `subs.SqsSubscription` to link them. The `app.synth()` call generates the CloudFormation template.
import os
import aws_cdk as cdk
import aws_cdk.aws_sns as sns
import aws_cdk.aws_sqs as sqs
import aws_cdk.aws_sns_subscriptions as subs
# A basic CDK App and Stack
class MySnsSubscriptionStack(cdk.Stack):
def __init__(self, scope: cdk.App, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
# Create an SQS queue to be subscribed
queue = sqs.Queue(self, "MySubscriptionQueue",
queue_name="MyTestSubscriptionQueue",
visibility_timeout=cdk.Duration.seconds(300)
)
# Create an SNS topic
topic = sns.Topic(self, "MySubscriptionTopic",
display_name="My Test Topic for Subscriptions"
)
# Subscribe the SQS queue to the SNS topic using SqsSubscription
topic.add_subscription(
subs.SqsSubscription(queue)
)
# Output the queue URL and topic ARN for verification
cdk.CfnOutput(self, "QueueUrl", value=queue.queue_url)
cdk.CfnOutput(self, "TopicArn", value=topic.topic_arn)
# Instantiate the CDK app and deployable stack
app = cdk.App()
MySnsSubscriptionStack(app, "MySnsSubscriptionStack")
app.synth() # Generates AWS CloudFormation template
Debug
Known issues
breakingAWS CDK v1 is in maintenance mode; AWS CDK v2 is the current major version. V1 packages like `aws-cdk-aws-sns-subscriptions` are replaced by a single `aws-cdk-lib` package in v2, which includes all constructs.fixMigrate your CDK applications to v2 by installing `aws-cdk-lib` and `constructs`, and updating imports. Refer to the official CDK migration guide for detailed steps: `https://docs.aws.amazon.com/cdk/v2/guide/migrating-v2.html`
affects: All v1.x versions
gotchaIn CDK v1, each service construct library (e.g., `aws-cdk.aws-sns`, `aws-cdk.aws-sqs`, `aws-cdk.aws-sns-subscriptions`) must be installed as a separate PyPI package. Forgetting to install all required dependencies is a common source of `ModuleNotFoundError`.fixEnsure all necessary CDK v1 modules are installed: `pip install aws-cdk.core aws-cdk.aws-sns aws-cdk.aws-sqs aws-cdk.aws-sns-subscriptions`. For v2, simply install `pip install aws-cdk-lib constructs`.
affects: All v1.x versions
gotchaWhen subscribing a resource (like an SQS queue or Lambda function) to an SNS topic, ensure the topic has the necessary permissions to send messages to that resource. While `SqsSubscription` often handles basic permissions, complex scenarios or custom policies might require explicit `addToResourcePolicy` calls on the receiving resource.fixReview the generated CloudFormation template for the subscription's IAM permissions. If messages are not being delivered, check the resource policy of the subscriber (e.g., `sqs.QueuePolicy` for SQS queues) to explicitly allow `sns:Publish` actions from the topic's ARN.
affects: All v1.x and v2.x versions
Upgrade
Version history
1.204.0latest on PyPI · released Jun 19, 2023
Audit
Dependencies
No dependency data recorded yet.