Alastair
Alastair

Reputation: 6114

SNS -> Lambda subscription doesn't work when set via API, but does when set by admin console

I'm setting up an SNS subscription for Lambda, using the Node aws-sdk. The call returns successfully - it gives me a subscription ARN, and when I look in the web console it appears. However, when I publish a message to the topic, nothing happens. I tried setting up the same subscription in the web console (all the fields look exactly the same) and it does work.

Is there something that the console does behind the scenes I'm not aware of? Sets permissions on the SNS topic/Lambda, anything like that?

Upvotes: 3

Views: 378

Answers (1)

Alastair
Alastair

Reputation: 6114

It turns out my suspicions about permissions were correct - you also need to add a Lambda.addPermission with the following pattern:

{
   FunctionName: functionArn,
   StatementId: Date.now().toString(),
   Action: 'lambda:InvokeFunction',
   Principal: 'sns.amazonaws.com',
   SourceArn: topicArn
}

Upvotes: 4

Related Questions