# CDK Construct Library for Amazon Simple Notification Service Subscriptions
<!--BEGIN STABILITY BANNER-->---
![Stability: Stable](https://img.shields.io/badge/stability-Stable-success.svg?style=for-the-badge)
---
<!--END STABILITY BANNER-->
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
Create an Amazon SNS Topic to add subscriptions.
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import aws_cdk.aws_sns as sns
my_topic = sns.Topic(self, "MyTopic")
```
### HTTPS
Add an HTTP or HTTPS Subscription to your topic:
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import aws_cdk.aws_sns_subscriptions as subscriptions
my_topic.add_subscription(subscriptions.UrlSubscription("https://foobar.com/"))
```
The URL being subscribed can also be [tokens](https://docs.aws.amazon.com/cdk/latest/guide/tokens.html), that resolve
to a URL during deployment. A typical use case is when the URL is passed in as a [CloudFormation
parameter](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html). The
following code defines a CloudFormation parameter and uses it in a URL subscription.
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
url = CfnParameter(self, "url-param")
my_topic.add_subscription(subscriptions.UrlSubscription(url.value_as_string()))
```
### Amazon SQS
Subscribe a queue to your topic:
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import aws_cdk.aws_sqs as sqs
import aws_cdk.aws_sns_subscriptions as subscriptions
my_queue = sqs.Queue(self, "MyQueue")
my_topic.add_subscription(subscriptions.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.
### AWS Lambda
Subscribe an AWS Lambda function to your topic:
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import aws_cdk.aws_lambda as lambda
import aws_cdk.aws_sns_subscriptions as subscriptions
my_function = lambda.Function(self, "Echo",
handler="index.handler",
runtime=lambda.Runtime.NODEJS_10_X,
code=lambda.Code.from_inline(f"exports.handler = {handler.toString()}")
)
my_topic.add_subscription(subscriptions.LambdaSubscription(my_function))
```
### Email
Subscribe an email address to your topic:
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
import aws_cdk.aws_sns_subscriptions as subscriptions
my_topic.add_subscription(subscriptions.EmailSubscription("foo@bar.com"))
```
The email being subscribed can also be [tokens](https://docs.aws.amazon.com/cdk/latest/guide/tokens.html), that resolve
to an email address during deployment. A typical use case is when the email address is passed in as a [CloudFormation
parameter](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html). The
following code defines a CloudFormation parameter and uses it in an email subscription.
```python
# Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
email_address = CfnParameter(self, "email-param")
my_topic.add_subscription(subscriptions.EmailSubscription(email_address.value_as_string()))
```
Note that email subscriptions require confirmation by visiting the link sent to the
email address.
没有合适的资源?快使用搜索试试~ 我知道了~
PyPI 官网下载 | aws-cdk.aws-sns-subscriptions-1.32.1.tar.gz
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 103 浏览量
2022-01-26
14:11:06
上传
评论
收藏 40KB GZ 举报
温馨提示
共15个文件
txt:4个
py:3个
pkg-info:2个
资源来自pypi官网。 资源全名:aws-cdk.aws-sns-subscriptions-1.32.1.tar.gz
资源推荐
资源详情
资源评论
收起资源包目录
aws-cdk.aws-sns-subscriptions-1.32.1.tar.gz (15个子文件)
aws-cdk.aws-sns-subscriptions-1.32.1
MANIFEST.in 23B
PKG-INFO 5KB
pyproject.toml 110B
src
aws_cdk
aws_sns_subscriptions
py.typed 1B
_jsii
__init__.py 290B
aws-sns-subscriptions@1.32.1.jsii.tgz 33KB
__init__.py 17KB
aws_cdk.aws_sns_subscriptions.egg-info
PKG-INFO 5KB
requires.txt 176B
SOURCES.txt 548B
top_level.txt 8B
dependency_links.txt 1B
setup.cfg 38B
setup.py 2KB
README.md 4KB
共 15 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功