-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sns] support for tokens in EmailSubscription #3996
Comments
This sounds good to me. We should make all the subscriptions consistent with using @strazeadin - are you able to send a PR to this effect? 😊 |
Hey, I've looked into implementing this as a PR and stumbled into an issue with my proposed solution. Utilizing the topic uniqueId will result in naming conflicts when you try and add multiple URL or Email subscriptions to the same topic (since they are using the same topic as the scope and the same unique ID as the identifier). SQS and Lambda can utilize the topic UniqueID due to the fact that they pass the queue or function respectively as the subscriberScope and therefore avoid conflicts that way. I also believe PR #2938 introduced a bug into the UrlSubscription similar to what my proposed solution would have done. If you subscribe to more than one unresolved URL you'll get the following error:
I'm currently unsure how to resolve this and looking for ideas around how to resolve both issues. Let me know if the above is clear or if I have missed anything obvious. Happy to hear any and all thoughts. |
You've identified a problem there for sure with The full solution we came up with looks something like below - In let id;
if (Token.isUnresolved(subscriptionConfig.subscriberId)) {
id = `${this.node.nextTokenChildPrefix()}:urlsubscription`;
} else {
id = subscriptionConfig.subscriberId;
} The Note that: On the other hand, you have the option to use the solution that we've used for |
Thanks for following up with a potential solution! Is it possible to go with a less intrusive solution of adding a simple At that point the id resolution will change to:
I believe this will have much less impact on the code base. The side-effect of this change is that you won't be able to provide an error message in case of subscribing the same subscriber to the same topic (which isn't ideal but doesn't cause any errors in deployment). Let me know your thoughts on my proposed solution. |
With the solution I suggested, I was hoping to use existing states to achieve this and avoid adding additional state. I was also hoping to make this reusable for other constructs that may have similar requirements. However, I'm ok with going with what you've suggested to begin with. Do note that this logic should apply ONLY to subscriptions that use tokens, and not otherwise. |
fixes aws#3996 to allow using tokens in email subscriptions, additionally fixes a bug with URL subscriptions when using more then one token subscription.
) 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 -->
🐛 Bug Report
What is the problem?
Creating an email subscription to an SNS topic when using an email address that is a token (for example, a CfnParameter) will fail with the following error:
"Cannot use tokens in construct ID"
Reproduction Steps
The below code will reproduce the error:
Environment
Other information
I believe the issue is coming from
aws-cdk/packages/@aws-cdk/aws-sns-subscriptions/lib/email.ts
Line 28 in 8870695
I'm not sure if there are other implications to this, the following code change solves the bug on my end:
this is a similar approach to
aws-cdk/packages/@aws-cdk/aws-sns-subscriptions/lib/sqs.ts
Line 48 in 8870695
Final note
Looking at the code for UrlSubscription:
aws-cdk/packages/@aws-cdk/aws-sns-subscriptions/lib/url.ts
Line 56 in 8870695
aws-cdk/packages/@aws-cdk/aws-sns/lib/subscriber.ts
Line 23 in 8870695
The text was updated successfully, but these errors were encountered: