Hello, how would I initialize a lambda that has no...
# help
k
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
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
@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
Ah yes, thanks!!