-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sns): support multiple tokens as url and email subscriptions (#6357
) fixes #3996 to allow using tokens in email subscriptions, additionally fixes a bug with URL subscriptions when using more than one token subscription. **The Issue** Email Subscriptions currently use the value passed in as the construct ID, when the value passed in is a token (For example a parameter) it causes an error as tokens aren't supported as construct IDs. A previous fix was done for URL Subscriptions but it also errors when more than one URL subscription with a token is used. **The fix** In the topic base, identify if the subscription ID is a token and override it to a valid construct ID. The method of ensuring a valid ID is to convert it to a special prefix suffixed by a number and doing an increment of the number for each new topic created with a token. Subscriptions not utilizing a token are not effected. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* <!-- Please read the contribution guidelines and follow the pull-request checklist: https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md -->
- Loading branch information
1 parent
b6d4d28
commit e5493bd
Showing
4 changed files
with
238 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,14 +31,24 @@ const myTopic = new sns.Topic(this, 'MyTopic'); | |
|
||
### HTTPS | ||
|
||
Add an HTTPS Subscription to your topic: | ||
Add an HTTP or HTTPS Subscription to your topic: | ||
|
||
```ts | ||
import subscriptions = require('@aws-cdk/aws-sns-subscriptions'); | ||
|
||
myTopic.addSubscription(new 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. | ||
|
||
```ts | ||
const url = new CfnParameter(this, 'url-param'); | ||
myTopic.addSubscription(new subscriptions.UrlSubscription(url.valueAsString())); | ||
``` | ||
|
||
### Amazon SQS | ||
|
||
Subscribe a queue to your topic: | ||
|
@@ -82,5 +92,15 @@ import subscriptions = require('@aws-cdk/aws-sns-subscriptions'); | |
myTopic.addSubscription(new subscriptions.EmailSubscription('[email protected]')); | ||
``` | ||
|
||
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. | ||
|
||
```ts | ||
const emailAddress = new CfnParameter(this, 'email-param'); | ||
myTopic.addSubscription(new subscriptions.EmailSubscription(emailAddress.valueAsString())); | ||
``` | ||
|
||
Note that email subscriptions require confirmation by visiting the link sent to the | ||
email address. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters