-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
fix(sns): allow tokens to be used in UrlSubscription #2938
fix(sns): allow tokens to be used in UrlSubscription #2938
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right that this needs a fix, but I would like to see the fix done differently.
Can you change it to only check if (!cdk.Token.isUnresolved(url)) { ...do the check ... }
.
You will be able to plug in SecretsManager values by going:
const url = secretsmanager.Secret.fromSecretAttributes(stack, 'Secret', { ... }).secretValue;
Or, if you really want to use the direct string construction, Token.asString('{{resolve:...}}')
.
11929e2
to
fb7d856
Compare
throw new Error('URL must start with either http:// or https://'); | ||
} | ||
} | ||
|
||
public bind(scope: Construct, topic: sns.ITopic): void { | ||
new sns.Subscription(scope, this.url, { | ||
new sns.Subscription(scope, topic.node.uniqueId + 'Url', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This avoids an error:
Error: Cannot use tokens in construct ID: ${Token[TOKEN.11]}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so it does. But now you can only add one URL subscription for any given topic.
Can you use the following expression instead?
Token.isUnresolved(this.url) ? 'UnresolvedUrl' : this.url
So we use the literal one if available, and only fall back to the reuse-breaking identifier if the URL is unresolved?
e6269e0
to
a0c71e6
Compare
a0c71e6
to
e48f892
Compare
@@ -23,17 +23,17 @@ export interface UrlSubscriptionProps extends SubscriptionProps { | |||
* @see https://docs.aws.amazon.com/sns/latest/dg/sns-http-https-endpoint-as-subscriber.html | |||
*/ | |||
export class UrlSubscription implements sns.ITopicSubscription { | |||
constructor(private readonly url: string, private readonly props: UrlSubscriptionProps = {}) { | |||
if (!url.startsWith('http://') && !url.startsWith('https://')) { | |||
constructor(private readonly url: string, private readonly protocol: sns.SubscriptionProtocol, private readonly props: UrlSubscriptionProps = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather have the protocol optionally inside the props, and derive it from the literal URL (if available).
Only force passing it if the URL is unresolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rix0rrr not sure what is happening with CodeBuild |
a6c350c
to
938bee4
Compare
} | ||
|
||
if (this.unresolvedUrl) { | ||
this.protocol = props.protocol!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The “!” shouldn’t be required here. Try to use !props.protocol above
Allows to pass in a dynamic reference as the
url
, like so:without having the CDK complain:
Pull Request Checklist
design
folderBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.