Skip to content

Commit

Permalink
Update index.ts
Browse files Browse the repository at this point in the history
Subscribe to existing topic, otherwise create
  • Loading branch information
LordAndreasOtten authored Dec 17, 2024
1 parent c15b24a commit 276e33d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,15 @@ class ServerlessOfflineSns {
);
}

this.log(`Creating topic: "${topicName}" for fn "${fnName}"`);
const data = await this.snsAdapter.createTopic(topicName);
const { Topics } = await this.snsAdapter.listTopics();

let data = Topics.find((sub) => sub.TopicArn.split(":").pop() === topicName);

if(!data || !data.TopicArn){
this.log(`Creating topic: "${topicName}" for fn "${fnName}"`);
data = await this.snsAdapter.createTopic(topicName);
}

this.debug("topic: " + JSON.stringify(data));
const handler = await this.createHandler(fnName, fn, lambdasLocation);
await this.snsAdapter.subscribe(
Expand Down Expand Up @@ -566,4 +573,4 @@ class ServerlessOfflineSns {
}
}

export default ServerlessOfflineSns;
export default ServerlessOfflineSns;

0 comments on commit 276e33d

Please sign in to comment.