Socket
Socket
Sign inDemoInstall

@aws-cdk/aws-sns

Package Overview
Dependencies
21
Maintainers
5
Versions
288
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @aws-cdk/aws-sns

The CDK Construct Library for AWS::SNS


Version published
Weekly downloads
117K
decreased by-1.47%
Maintainers
5
Created
Weekly downloads
 

Changelog

Source

1.67.0 (2020-10-07)

⚠ BREAKING CHANGES TO EXPERIMENTAL FEATURES

  • monodk-experiment: This package is now deprected in favor of monocdk. Note that monocdk is still experimental.

Features

Bug Fixes

  • cli: 'stack already contains Metadata resource' warning (#10695) (e0b5508), closes #10625
  • cli: deploying a transformed template without changes fails (#10689) (d345919), closes #10650
  • cloudfront-origins: S3Origins with cross-stack buckets cause cyclic references (#10696) (0ec4588), closes #10399
  • codepipeline-actions: correctly name the triggering Event in CodeCommitSourceAction (#10706) (ff3a692), closes #10665
  • core: cannot override properties with . in the name (#10441) (063798b), closes #10109
  • core: Stacks from 3rd-party libraries do not synthesize correctly (#10690) (7bb5cf4), closes #10671
  • ec2: addExecuteFileCommand arguments cannot be omitted (#10692) (7178374), closes #10687
  • ec2: InitCommand.shellCommand() renders an argv command instead (#10691) (de9d2f7), closes #10684
  • ec2: memory optimised graviton2 instance type (#10615) (a72cfbd)
  • elbv2: metric(Un)HealthyHostCount don't use TargetGroup dimension (#10697) (9444399), closes #5046
  • glue: GetTableVersion permission not available for read (#10628) (b0c5699), closes #10577
  • glue: incorrect s3 prefix used for grant* in Table (#10627) (4d20079), closes #10582
  • pipelines: cannot use constructs in build environment (#10654) (bf2c629), closes #10535
  • pipelines: pipeline doesn't restart if CLI version changes (#10727) (0297f31), closes #10659
  • rds: secret for ServerlessCluster is not accessible programmatically (#10657) (028495e)
  • redshift: Allow redshift cluster securityGroupName to be generated (#10742) (effed09), closes #10740
  • stepfunctions: X-Ray policy does not match documentation (#10721) (8006459)

Readme

Source

Amazon Simple Notification Service Construct Library


cfn-resources: Stable

cdk-constructs: Stable


Add an SNS Topic to your stack:

import * as sns from '@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 * as subs from '@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
// store: attribute must be present
topic.addSubscription(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
        }),
        store: sns.SubscriptionFilter.existsFilter(),
    }
}));

DLQ setup for SNS Subscription

CDK can attach provided Queue as DLQ for your SNS subscription. See the SNS DLQ configuration docs for more information about this feature.

Example of usage with user provided DLQ.

const topic = new sns.Topic(stack, 'Topic');
const dlQueue = new Queue(stack, 'DeadLetterQueue', {
    queueName: 'MySubscription_DLQ',
    retentionPeriod: cdk.Duration.days(14),
});

new sns.Subscription(stack, 'Subscription', {
    endpoint: 'endpoint',
    protocol: sns.SubscriptionProtocol.LAMBDA,
    topic,
    deadLetterQueue: dlQueue,
});

CloudWatch Event Rule Target

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

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

import * as targets from '@aws-cdk/aws-events-targets';

codeCommitRepository.onCommit(new targets.SnsTopic(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.

Keywords

FAQs

Last updated on 07 Oct 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc