aws-cdk
aws-cdk copied to clipboard
SNS Lambda Subscription Conflict
When subscribing multiple SNS Topics to a single Lambda Function, if two of those Topics have the same id (scope-local - this could happen if those Topics are in different scopes) then the second subscription will fail to be created with:
A subscription with id "SomeId" already exists under the scope Stack/Resource
Reproduction Steps
See robwettach/sns-lambda-subscription-conflict
Error Log
A subscription with id "SomeId" already exists under the scope Stack/Resource
Environment
- CLI Version : 1.37.0 (build e4709de)
- Framework Version: 1.37.0
- OS : macOS Mojave 10.14.6
- Language : TypeScript (all)
Other
I believe changing this line from
subscriberId: topic.node.id,
to
subscriberId: topic.node.uniqueId,
will solve this issue.
This is :bug: Bug Report
Note that the SQS Subscription does this properly.
I just ran into this same issue again over a year later. In this case I created a sns.Topic within an enclosing construct and set its id to "Resource". This of course clashes with the default name of basically any other resource.
One of our SST users ran into the same issue. I just submitted a PR for this.
I just ran into the same problem. I also have an sns.Topic within a custom construct. @fwang, thanks for the PR!
No updates here??
I have the same error message, but different setup. I'm importing the topic using:
const topic = sns.Topic.fromTopicArn(
this,
'topic-id'
`arn-goes-here`,
);
this.addEventSource(new SnsEventSource(topic));
And then I'm getting this error message:
Error: A subscription with id "topic-id" already exists under the scope stack-name/lambda-id
My Lambda is wrapped over a custom construct, so I think it's not only a problem of wrapping the Topic in a custom construct
I also managed to workaround it, by extracting the sns.Topic.fromTopicArn( [...] ) call out of custom Lambda construct to one level up and then passing it as props.