question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SNS Lambda Subscription Conflict

See original GitHub issue

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 Report

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

1reaction
JelsBcommented, Feb 18, 2022

I just ran into the same problem. I also have an sns.Topic within a custom construct. @fwang, thanks for the PR!

0reactions
PatrykMilewskicommented, Oct 5, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Amazon SNS not invoking a Lambda function
1. View your Lambda function's SNS topic subscription filter policy by doing the following: Open the Amazon SNS console. On the left navigation ......
Read more >
AWS-Lambda and SNS : cross account - 2021 - BogoToBogo
From account B, subscribe the Lambda function to the topic. When a message is sent to the lambda-x-account topic in account A (047109936880),...
Read more >
AWS Lambda triggered by SNS, can I catch exceptions from ...
It's not possible with a vanilla SNS trigger. The trigger has no knowledge of what happens after it fires. The easiest solution is...
Read more >
Monitoring SNS Activity Using a Lambda Function and ...
To subscribe your Lambda function to the SNS topic you created, go back to the main Amazon Web Services page, and click the...
Read more >
Building a CI/CD pipeline for an AWS Lambda function using ...
The integration layer of the serverless application uses S3 triggers to subscribe to the input events and an SNS client to write output ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found