Hello, I'm trying to replicate a behaviour that I ...
# help
h
Hello, I'm trying to replicate a behaviour that I have in SLS which is to have multiple SNS topics send messages to one Lambda. Effectively One Lambda Subscribing 2 topics. However this doesn't seem to be allowed?
Copy code
Error: A subscription with id "Topic" already exists under the scope dev-*-metadata-stack/UpdateSnapshot
    at Topic.addSubscription (/home/dev/Documents/*/Github/*/node_modules/aws-cdk-lib/aws-sns/lib/topic-base.ts:61:13)
    at Topic.addFunctionSubscriber (/home/dev/Documents/*/Github/*/node_modules/@serverless-stack/resources/src/Topic.ts:231:19)
    at Topic.addSubscriber (/home/dev/Documents/*/Github/*/node_modules/@serverless-stack/resources/src/Topic.ts:176:12)
    at /home/dev/Documents/*/Github/*/node_modules/@serverless-stack/resources/src/Topic.ts:125:46
    at Array.forEach (<anonymous>)
    at Topic.addSubscribers (/home/dev/Documents/*/Github/*/node_modules/@serverless-stack/resources/src/Topic.ts:125:17)
    at new MetadataStack (/home/dev/Documents/*/Github/*/lib/metadataStack.js:231:22)
    at Object.main (/home/dev/Documents/*/Github/*/lib/index.js:125:39)
    at Object.<anonymous> (/home/dev/Documents/*/Github/*/.build/run.js:94:16)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
Any ideas of a work around? Thanks!
t
Can I see your cdk code
also what version of SST are you on?
h
I've defined the Topics "lazily" and i'm adding subscribers in the stacks that define the functions (just because its easier and cleaner that way (i think).
Copy code
props.topicA.addSubscribers(this, [
      {
        function: updateSnapshot,
        subscriberProps: {
          filterPolicy: {
            event_type: SubscriptionFilter.stringFilter({
              allowlist: ["file_created"],
            }),
          },
        },
      },
    ]);

    props.topicB.addSubscribers(this, [
      {
        function: updateSnapshot,
        subscriberProps: {
          filterPolicy: {
            event_type: SubscriptionFilter.stringFilter({
              allowlist: ["state_changed"],
            }),
          },
        },
      },
    ]);
This is a snippet that flags up. SST version @ latest.
t
I vaguely recall this being brought up and I think we maybe fixed it - @Frank?
h
Any updates on this? @thdxr thanks
f
Taking a look..
h
Sorry to ask again 🙈 but is there any update? I sort of have a work around so its not "urgent" just wondering if this was in any way fixed and not included in the patch notes.
f
Hey @Hubert, sorry about the delay. I just tried it out. I’m guess the two topics
props.topicA
and
props.topicB
have the same id ^^ ie. id is the 2nd parameter passed into the constructor
new sst.Topic(this, "topicId", {…});
If that’s the case, can you try change the id of on the topic and give it a try?
h
Thanks for getting back to me! All my topics have a unique ID I've made sure that's the case for every single resource. This is only an issue when attaching one function to two topics as a subscriber. Hence why I assumed that the topics themselves aren't at fault because they work if I dont setup the subscribers.
f
Hey @Hubert, I dug into this a bit further, and it seems to be a case that’s not handled by CDK.
I submitted a PR to CDK with the fix https://github.com/aws/aws-cdk/pull/19028
In the mean while, i guess you’d have to create two subscribers with the same code.
h
Thanks for that Frank, sorry for the late reply. I will keep an eye on the github page. I'm going to implement what you've suggested as a temporary solution 🙂 thanks!