https://serverless-stack.com/ logo
#help
Title
# help
k

Krizza

12/16/2021, 7:34 AM
Hello, how would I initialize a lambda that has no triggers? It’s actually triggered by SNS but we have multiple SNS topics and from different accounts and it will continue to scale up. The only example I saw required me to create an SNS topic first and then adding the lambdas in the subscribers property
b

Brinsley

12/16/2021, 8:42 AM
I’m not sure if this answers your question but you can reference an SNS Topic by using static functions on the
Topic
construct. Most of the SST construct static methods for importing resources. Once you’ve got the reference you should be able to add the lambda to trigger how you describe.
Ah, looks like the SST construct doesn’t have it, it’s the CDK
Topic
class you want: use
fromTopicArn
.
f

Frank

12/18/2021, 12:08 PM
@Krizza do you mean creating a Function on it’s own like this?
Copy code
const fn = new sst.Function(this, "MyFn", {
  handler: "src/lambda.main";
});
And then add it as the subscriber to multiple Topics like this?
Copy code
new sst.Topic(this, "MyTopicA", {
  subscribers: [fn];
});
new sst.Topic(this, "MyTopicB", {
  subscribers: [fn];
});
Is this what you mean?
k

Krizza

01/03/2022, 4:27 AM
Ah yes, thanks!!