AWS CDK SNS Construct Library (v1)

1.204.0 · maintenance · verified Thu Apr 16

The `aws-cdk-aws-sns` library provides AWS Cloud Development Kit (CDK) constructs specifically for AWS Simple Notification Service (SNS) resources. This package is part of AWS CDK v1, which is currently in maintenance mode. For new projects, it is strongly recommended to use AWS CDK v2 and the consolidated `aws-cdk-lib` package. AWS CDK generally has a rapid release cadence, with minor versions released frequently, and major versions (like v2) introducing significant changes.

Common errors

Warnings

Install

Imports

Quickstart

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()

view raw JSON →