Lambda not triggered by SNS publish > topics created programmatically


I have a Lambda (lambda_a) subscribed to a topic, but it’s not been triggered on publish. I believe the problem is that, in the serverless.yml, I don’t have event > sns > arn:

If I put a topic arn, everything works as expected :slight_smile:

But here is the catch: my lambda_a subscribes and unsubscribes from topics through AWS API calls. I have another lambda (lambda_b) that generates a bunch of new topics at run time and lambda_a subscribes to them (this is actually working, I can see in SNS dashboard that lambda_a is subscribed to my_new_topic)

In other words, it looks like the problem is that I don’t have in serverless.yml event > sns > arn: my_new_topic, because I actually don’t have the topic at deploy time

Any thoughts on this? Thanks!

For reference, a snippet from my serverless.yml:

      - Effect: Allow
          - lambda:InvokeFunction
        Resource: "arn:aws:lambda:<region>:<number>:function:lambda_a"
      - Effect: Allow
          - sns:*
        Resource: arn:aws:sns:<region>:<number>:*
        handler: handlers/my_handler:
          - http:
                path: some/path
                method: post
                authorizer: my_authorizer