awssnssubscriptions

package
v2.63.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2023 License: Apache-2.0 Imports: 8 Imported by: 3

README

CDK Construct Library for Amazon Simple Notification Service Subscriptions

This library provides constructs for adding subscriptions to an Amazon SNS topic. Subscriptions can be added by calling the .addSubscription(...) method on the topic.

Subscriptions

Subscriptions can be added to the following endpoints:

  • HTTPS
  • Amazon SQS
  • AWS Lambda
  • Email
  • SMS

Subscriptions to Amazon SQS and AWS Lambda can be added on topics across regions.

Create an Amazon SNS Topic to add subscriptions.

myTopic := sns.NewTopic(this, jsii.String("MyTopic"))
HTTPS

Add an HTTP or HTTPS Subscription to your topic:

myTopic := sns.NewTopic(this, jsii.String("MyTopic"))

myTopic.addSubscription(subscriptions.NewUrlSubscription(jsii.String("https://foobar.com/")))

The URL being subscribed can also be tokens, that resolve to a URL during deployment. A typical use case is when the URL is passed in as a CloudFormation parameter. The following code defines a CloudFormation parameter and uses it in a URL subscription.

myTopic := sns.NewTopic(this, jsii.String("MyTopic"))
url := awscdk.NewCfnParameter(this, jsii.String("url-param"))

myTopic.addSubscription(subscriptions.NewUrlSubscription(url.valueAsString))
Amazon SQS

Subscribe a queue to your topic:

myQueue := sqs.NewQueue(this, jsii.String("MyQueue"))
myTopic := sns.NewTopic(this, jsii.String("MyTopic"))

myTopic.addSubscription(subscriptions.NewSqsSubscription(myQueue))

KMS key permissions will automatically be granted to SNS when a subscription is made to an encrypted 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.

AWS Lambda

Subscribe an AWS Lambda function to your topic:

import lambda "github.com/aws/aws-cdk-go/awscdk"
var myFunction function


myTopic := sns.NewTopic(this, jsii.String("myTopic"))
myTopic.addSubscription(subscriptions.NewLambdaSubscription(myFunction))
Email

Subscribe an email address to your topic:

myTopic := sns.NewTopic(this, jsii.String("MyTopic"))
myTopic.addSubscription(subscriptions.NewEmailSubscription(jsii.String("foo@bar.com")))

The email being subscribed can also be tokens, that resolve to an email address during deployment. A typical use case is when the email address is passed in as a CloudFormation parameter. The following code defines a CloudFormation parameter and uses it in an email subscription.

myTopic := sns.NewTopic(this, jsii.String("Topic"))
emailAddress := awscdk.NewCfnParameter(this, jsii.String("email-param"))

myTopic.addSubscription(subscriptions.NewEmailSubscription(emailAddress.valueAsString))

Note that email subscriptions require confirmation by visiting the link sent to the email address.

SMS

Subscribe an sms number to your topic:

myTopic := sns.NewTopic(this, jsii.String("Topic"))

myTopic.addSubscription(subscriptions.NewSmsSubscription(jsii.String("+15551231234")))

The number being subscribed can also be tokens, that resolve to a number during deployment. A typical use case is when the number is passed in as a CloudFormation parameter. The following code defines a CloudFormation parameter and uses it in an sms subscription.

myTopic := sns.NewTopic(this, jsii.String("Topic"))
smsNumber := awscdk.NewCfnParameter(this, jsii.String("sms-param"))

myTopic.addSubscription(subscriptions.NewSmsSubscription(smsNumber.valueAsString))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEmailSubscription_Override

func NewEmailSubscription_Override(e EmailSubscription, emailAddress *string, props *EmailSubscriptionProps)

func NewLambdaSubscription_Override

func NewLambdaSubscription_Override(l LambdaSubscription, fn awslambda.IFunction, props *LambdaSubscriptionProps)

func NewSmsSubscription_Override

func NewSmsSubscription_Override(s SmsSubscription, phoneNumber *string, props *SmsSubscriptionProps)

func NewSqsSubscription_Override

func NewSqsSubscription_Override(s SqsSubscription, queue awssqs.IQueue, props *SqsSubscriptionProps)

func NewUrlSubscription_Override

func NewUrlSubscription_Override(u UrlSubscription, url *string, props *UrlSubscriptionProps)

Types

type EmailSubscription

type EmailSubscription interface {
	awssns.ITopicSubscription
	// Returns a configuration for an email address to subscribe to an SNS topic.
	Bind(_topic awssns.ITopic) *awssns.TopicSubscriptionConfig
}

Use an email address as a subscription target.

Email subscriptions require confirmation.

Example:

myTopic := sns.NewTopic(this, jsii.String("Topic"))
emailAddress := awscdk.NewCfnParameter(this, jsii.String("email-param"))

myTopic.addSubscription(subscriptions.NewEmailSubscription(emailAddress.valueAsString))

func NewEmailSubscription

func NewEmailSubscription(emailAddress *string, props *EmailSubscriptionProps) EmailSubscription

type EmailSubscriptionProps

type EmailSubscriptionProps struct {
	// Queue to be used as dead letter queue.
	//
	// If not passed no dead letter queue is enabled.
	DeadLetterQueue awssqs.IQueue `field:"optional" json:"deadLetterQueue" yaml:"deadLetterQueue"`
	// The filter policy.
	FilterPolicy *map[string]awssns.SubscriptionFilter `field:"optional" json:"filterPolicy" yaml:"filterPolicy"`
	// Indicates if the full notification JSON should be sent to the email address or just the message text.
	Json *bool `field:"optional" json:"json" yaml:"json"`
}

Options for email subscriptions.

Example:

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var queue queue
var subscriptionFilter subscriptionFilter

emailSubscriptionProps := &emailSubscriptionProps{
	deadLetterQueue: queue,
	filterPolicy: map[string]*subscriptionFilter{
		"filterPolicyKey": subscriptionFilter,
	},
	json: jsii.Boolean(false),
}

type LambdaSubscription

type LambdaSubscription interface {
	awssns.ITopicSubscription
	// Returns a configuration for a Lambda function to subscribe to an SNS topic.
	Bind(topic awssns.ITopic) *awssns.TopicSubscriptionConfig
}

Use a Lambda function as a subscription target.

Example:

import lambda "github.com/aws/aws-cdk-go/awscdk"
var fn function

myTopic := sns.NewTopic(this, jsii.String("MyTopic"))

// 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
myTopic.addSubscription(subscriptions.NewLambdaSubscription(fn, &lambdaSubscriptionProps{
	filterPolicy: map[string]subscriptionFilter{
		"color": sns.*subscriptionFilter.stringFilter(&StringConditions{
			"allowlist": []*string{
				jsii.String("red"),
				jsii.String("orange"),
			},
			"matchPrefixes": []*string{
				jsii.String("bl"),
			},
		}),
		"size": sns.*subscriptionFilter.stringFilter(&StringConditions{
			"denylist": []*string{
				jsii.String("small"),
				jsii.String("medium"),
			},
		}),
		"price": sns.*subscriptionFilter.numericFilter(&NumericConditions{
			"between": &BetweenCondition{
				"start": jsii.Number(100),
				"stop": jsii.Number(200),
			},
			"greaterThan": jsii.Number(300),
		}),
		"store": sns.*subscriptionFilter.existsFilter(),
	},
}))

type LambdaSubscriptionProps

type LambdaSubscriptionProps struct {
	// Queue to be used as dead letter queue.
	//
	// If not passed no dead letter queue is enabled.
	DeadLetterQueue awssqs.IQueue `field:"optional" json:"deadLetterQueue" yaml:"deadLetterQueue"`
	// The filter policy.
	FilterPolicy *map[string]awssns.SubscriptionFilter `field:"optional" json:"filterPolicy" yaml:"filterPolicy"`
}

Properties for a Lambda subscription.

Example:

import lambda "github.com/aws/aws-cdk-go/awscdk"
var fn function

myTopic := sns.NewTopic(this, jsii.String("MyTopic"))

// 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
myTopic.addSubscription(subscriptions.NewLambdaSubscription(fn, &lambdaSubscriptionProps{
	filterPolicy: map[string]subscriptionFilter{
		"color": sns.*subscriptionFilter.stringFilter(&StringConditions{
			"allowlist": []*string{
				jsii.String("red"),
				jsii.String("orange"),
			},
			"matchPrefixes": []*string{
				jsii.String("bl"),
			},
		}),
		"size": sns.*subscriptionFilter.stringFilter(&StringConditions{
			"denylist": []*string{
				jsii.String("small"),
				jsii.String("medium"),
			},
		}),
		"price": sns.*subscriptionFilter.numericFilter(&NumericConditions{
			"between": &BetweenCondition{
				"start": jsii.Number(100),
				"stop": jsii.Number(200),
			},
			"greaterThan": jsii.Number(300),
		}),
		"store": sns.*subscriptionFilter.existsFilter(),
	},
}))

type SmsSubscription

type SmsSubscription interface {
	awssns.ITopicSubscription
	// Returns a configuration used to subscribe to an SNS topic.
	Bind(_topic awssns.ITopic) *awssns.TopicSubscriptionConfig
}

Use an sms address as a subscription target.

Example:

myTopic := sns.NewTopic(this, jsii.String("Topic"))

myTopic.addSubscription(subscriptions.NewSmsSubscription(jsii.String("+15551231234")))

func NewSmsSubscription

func NewSmsSubscription(phoneNumber *string, props *SmsSubscriptionProps) SmsSubscription

type SmsSubscriptionProps

type SmsSubscriptionProps struct {
	// Queue to be used as dead letter queue.
	//
	// If not passed no dead letter queue is enabled.
	DeadLetterQueue awssqs.IQueue `field:"optional" json:"deadLetterQueue" yaml:"deadLetterQueue"`
	// The filter policy.
	FilterPolicy *map[string]awssns.SubscriptionFilter `field:"optional" json:"filterPolicy" yaml:"filterPolicy"`
}

Options for SMS subscriptions.

Example:

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var queue queue
var subscriptionFilter subscriptionFilter

smsSubscriptionProps := &smsSubscriptionProps{
	deadLetterQueue: queue,
	filterPolicy: map[string]*subscriptionFilter{
		"filterPolicyKey": subscriptionFilter,
	},
}

type SqsSubscription

type SqsSubscription interface {
	awssns.ITopicSubscription
	// Returns a configuration for an SQS queue to subscribe to an SNS topic.
	Bind(topic awssns.ITopic) *awssns.TopicSubscriptionConfig
}

Use an SQS queue as a subscription target.

Example:

var queue queue

myTopic := sns.NewTopic(this, jsii.String("MyTopic"))

myTopic.addSubscription(subscriptions.NewSqsSubscription(queue))

func NewSqsSubscription

func NewSqsSubscription(queue awssqs.IQueue, props *SqsSubscriptionProps) SqsSubscription

type SqsSubscriptionProps

type SqsSubscriptionProps struct {
	// Queue to be used as dead letter queue.
	//
	// If not passed no dead letter queue is enabled.
	DeadLetterQueue awssqs.IQueue `field:"optional" json:"deadLetterQueue" yaml:"deadLetterQueue"`
	// The filter policy.
	FilterPolicy *map[string]awssns.SubscriptionFilter `field:"optional" json:"filterPolicy" yaml:"filterPolicy"`
	// The message to the queue is the same as it was sent to the topic.
	//
	// If false, the message will be wrapped in an SNS envelope.
	RawMessageDelivery *bool `field:"optional" json:"rawMessageDelivery" yaml:"rawMessageDelivery"`
}

Properties for an SQS subscription.

Example:

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var queue queue
var subscriptionFilter subscriptionFilter

sqsSubscriptionProps := &sqsSubscriptionProps{
	deadLetterQueue: queue,
	filterPolicy: map[string]*subscriptionFilter{
		"filterPolicyKey": subscriptionFilter,
	},
	rawMessageDelivery: jsii.Boolean(false),
}

type SubscriptionProps

type SubscriptionProps struct {
	// Queue to be used as dead letter queue.
	//
	// If not passed no dead letter queue is enabled.
	DeadLetterQueue awssqs.IQueue `field:"optional" json:"deadLetterQueue" yaml:"deadLetterQueue"`
	// The filter policy.
	FilterPolicy *map[string]awssns.SubscriptionFilter `field:"optional" json:"filterPolicy" yaml:"filterPolicy"`
}

Options to subscribing to an SNS topic.

Example:

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var queue queue
var subscriptionFilter subscriptionFilter

subscriptionProps := &subscriptionProps{
	deadLetterQueue: queue,
	filterPolicy: map[string]*subscriptionFilter{
		"filterPolicyKey": subscriptionFilter,
	},
}

type UrlSubscription

type UrlSubscription interface {
	awssns.ITopicSubscription
	// Returns a configuration for a URL to subscribe to an SNS topic.
	Bind(_topic awssns.ITopic) *awssns.TopicSubscriptionConfig
}

Use a URL as a subscription target.

The message will be POSTed to the given URL.

Example:

myTopic := sns.NewTopic(this, jsii.String("MyTopic"))

myTopic.addSubscription(subscriptions.NewUrlSubscription(jsii.String("https://foobar.com/")))

See: https://docs.aws.amazon.com/sns/latest/dg/sns-http-https-endpoint-as-subscriber.html

func NewUrlSubscription

func NewUrlSubscription(url *string, props *UrlSubscriptionProps) UrlSubscription

type UrlSubscriptionProps

type UrlSubscriptionProps struct {
	// Queue to be used as dead letter queue.
	//
	// If not passed no dead letter queue is enabled.
	DeadLetterQueue awssqs.IQueue `field:"optional" json:"deadLetterQueue" yaml:"deadLetterQueue"`
	// The filter policy.
	FilterPolicy *map[string]awssns.SubscriptionFilter `field:"optional" json:"filterPolicy" yaml:"filterPolicy"`
	// The subscription's protocol.
	Protocol awssns.SubscriptionProtocol `field:"optional" json:"protocol" yaml:"protocol"`
	// The message to the queue is the same as it was sent to the topic.
	//
	// If false, the message will be wrapped in an SNS envelope.
	RawMessageDelivery *bool `field:"optional" json:"rawMessageDelivery" yaml:"rawMessageDelivery"`
}

Options for URL subscriptions.

Example:

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var queue queue
var subscriptionFilter subscriptionFilter

urlSubscriptionProps := &urlSubscriptionProps{
	deadLetterQueue: queue,
	filterPolicy: map[string]*subscriptionFilter{
		"filterPolicyKey": subscriptionFilter,
	},
	protocol: awscdk.Aws_sns.subscriptionProtocol_HTTP,
	rawMessageDelivery: jsii.Boolean(false),
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL