Skip to main content

CDK Constructs for AWS SNS

Project description

Amazon Simple Notification Service Construct Library

---

Stability: Stable


Add an SNS Topic to your stack:

# Example may have issues. See https://github.com/aws/jsii/issues/826
import aws_cdk.aws_sns as sns

topic = sns.Topic(self, "Topic",
    display_name="Customer subscription topic"
)

Subscriptions

Various subscriptions can be added to the topic by calling the .addSubscription(...) method on the topic. It accepts a subscription object, default implementations of which can be found in the @aws-cdk/aws-sns-subscriptions package:

Add an HTTPS Subscription to your topic:

# Example may have issues. See https://github.com/aws/jsii/issues/826
import aws_cdk.aws_sns_subscriptions as subs

my_topic = sns.Topic(self, "MyTopic")

my_topic.add_subscription(subs.UrlSubscription("https://foobar.com/"))

Subscribe a queue to the topic:

# Example may have issues. See https://github.com/aws/jsii/issues/826
my_topic.add_subscription(subs.SqsSubscription(queue))

Note that subscriptions of queues in different accounts need to be manually confirmed by reading the initial message from the queue and visiting the link found in it.

Filter policy

A filter policy can be specified when subscribing an endpoint to a topic.

Example with a Lambda subscription:

# Example may have issues. See https://github.com/aws/jsii/issues/826
my_topic = sns.Topic(self, "MyTopic")
fn = lambda.Function(self, "Function", ...)

# Lambda should receive only message matching the following conditions on attributes:
# color: 'red' or 'orange' or begins with 'bl'
# size: anything but 'small' or 'medium'
# price: between 100 and 200 or greater than 300
# store: attribute must be present
topic.subscribe_lambda(subs.LambdaSubscription(fn,
    filter_policy={
        "color": sns.SubscriptionFilter.string_filter(
            whitelist=["red", "orange"],
            match_prefixes=["bl"]
        ),
        "size": sns.SubscriptionFilter.string_filter(
            blacklist=["small", "medium"]
        ),
        "price": sns.SubscriptionFilter.numeric_filter(
            between={"start": 100, "stop": 200},
            greater_than=300
        ),
        "store": sns.SubscriptionFilter.exists_filter()
    }
))

CloudWatch Event Rule Target

SNS topics can be used as targets for CloudWatch event rules.

Use the @aws-cdk/aws-events-targets.SnsTopicTarget:

# Example may have issues. See https://github.com/aws/jsii/issues/826
import aws_cdk.aws_events_targets as targets

code_commit_repository.on_commit(targets.SnsTopicTarget(my_topic))

This will result in adding a target to the event rule and will also modify the topic resource policy to allow CloudWatch events to publish to the topic.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws-cdk.aws-sns-1.14.0.tar.gz (69.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aws_cdk.aws_sns-1.14.0-py3-none-any.whl (66.2 kB view details)

Uploaded Python 3

File details

Details for the file aws-cdk.aws-sns-1.14.0.tar.gz.

File metadata

  • Download URL: aws-cdk.aws-sns-1.14.0.tar.gz
  • Upload date:
  • Size: 69.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.5

File hashes

Hashes for aws-cdk.aws-sns-1.14.0.tar.gz
Algorithm Hash digest
SHA256 cadd53ed20c6a07829252eeb7a7f983b6c48e3e8c685ec2e968aaf25be1e1e90
MD5 a1a97e447bbacd99a8a1329d47bd6c35
BLAKE2b-256 aaef9e4ead3cf15e012e4f6aee7a679a29555ab1574705897eda6ba15431f9bf

See more details on using hashes here.

File details

Details for the file aws_cdk.aws_sns-1.14.0-py3-none-any.whl.

File metadata

  • Download URL: aws_cdk.aws_sns-1.14.0-py3-none-any.whl
  • Upload date:
  • Size: 66.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.5

File hashes

Hashes for aws_cdk.aws_sns-1.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8688f261617381ac9ca8f4e0b3ddbde7363e488f16bd35246b84e17cf354992
MD5 e7f15b67fa797fc546f4ba06adea46b3
BLAKE2b-256 f61cf97fda8563e406f125ed5e4c782382988a3938cc25e87e84ab7bcf98d4cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page