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:

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-1.6.1.tar.gz (68.0 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.6.1-py3-none-any.whl (65.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aws-cdk.aws-sns-1.6.1.tar.gz
  • Upload date:
  • Size: 68.0 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.35.0 CPython/3.6.5

File hashes

Hashes for aws-cdk.aws-sns-1.6.1.tar.gz
Algorithm Hash digest
SHA256 390bddd3fe95b66aea89300ef2dde0df1ff531f8b874838022d41e3e62bed291
MD5 12f0d4ab3d72c4dc3ddf595bb79e8960
BLAKE2b-256 ffeeeac61cda10c8783dcc879fcef751a74e47d395a57f31beccfe5bf437f5ec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aws_cdk.aws_sns-1.6.1-py3-none-any.whl
  • Upload date:
  • Size: 65.1 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.35.0 CPython/3.6.5

File hashes

Hashes for aws_cdk.aws_sns-1.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d801ec6d1037bca56eba727dfc990bcbccc02a11bac2cd9c19d6bd8cda937aeb
MD5 5d17eef7fe399e76dea14552a3737572
BLAKE2b-256 250e5f3e75761f895a1c3c1ac901facbd7717a259083c1ecae347c98150139fd

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