Skip to main content

CDK Constructs for AWS SNS

Project description

Amazon Simple Notification Service Construct Library


Stability: Experimental

This is a developer preview (public beta) module. Releases might lack important features and might have future breaking changes.

This API is still under active development and subject to non-backward compatible changes or removal in any future version. Use of the API is not recommended in production environments. Experimental APIs are not subject to the Semantic Versioning model.


Add an SNS Topic to your stack:

import sns = require('@aws-cdk/aws-sns');

const topic = new sns.Topic(this, 'Topic', {
    displayName: '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:

import subs = require('@aws-cdk/aws-sns-subscriptions');

const myTopic = new sns.Topic(this, 'MyTopic');

myTopic.addSubscription(new subs.UrlSubscription('https://foobar.com/'));

Subscribe a queue to the topic:

myTopic.addSubscription(new 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:

const myTopic = new sns.Topic(this, 'MyTopic');
const fn = new lambda.Function(this, '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
topic.subscribeLambda(new subs.LambdaSubscription(fn, {
    filterPolicy: {
        color: sns.SubscriptionFilter.stringFilter({
            whitelist: ['red', 'orange'],
            matchPrefixes: ['bl']
        }),
        size: sns.SubscriptionFilter.stringFilter({
            blacklist: ['small', 'medium'],
        }),
        price: sns.SubscriptionFilter.numericFilter({
            between: { start: 100, stop: 200 },
            greaterThan: 300
        })
    }
}));

CloudWatch Event Rule Target

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

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

import targets = require('@aws-cdk/aws-events-targets');

codeCommitRepository.onCommit(new targets.SnsTopicTarget(myTopic));

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-0.36.0.tar.gz (62.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-0.36.0-py3-none-any.whl (61.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for aws-cdk.aws-sns-0.36.0.tar.gz
Algorithm Hash digest
SHA256 2fe0fe6d474a9e142b1486f7eff6ee7fdef16a8745f71e19444f72b91e9c4dcc
MD5 67da1f01332799238a3b423ca01e8624
BLAKE2b-256 7894a22871457aeddd72a4a7455b328a17e4dfc2b86596ed70ec2eb338e373b6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for aws_cdk.aws_sns-0.36.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b42bbd14de82f756629d26e5b559beb0d7756cb59ee95f13f6d251803d8bc2cd
MD5 f86a118a0ecf50e158dcc07237b32d88
BLAKE2b-256 1a5026ab6ef4f7d0fe28251952eff4b70b5549c90c7de6cd53a09516c744d3b3

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