8
votes

I have a Lambda function deployed to several regions. I would like to publish a message to SNS that will invoke these functions.

Using aws-cli I've created the topics, given Lambda permission to talk to SNS, and create the subscriptions. The subscription appears to be created successfully, and I can see it in the AWS console. But, it doesn't work. The lambda function does not get invoked.

1
Have you added the subscription as the event source in the lambda function settings?Assaf Lavie
Thanks for the question @AssafLavie. I have not done this specifically but I don't believe it's necessary when invoking from SNS or S3.Shane H
To clarify, I can replicate this in a simpler example by creating an SNS topic with a single subscriber in a different region. In that case I publish a message to the topic but the function is never invoked. It seems permissions related but I can't see anything specific to going inter-regionShane H

1 Answers

9
votes

This is CloudFormation based example. You have to add invoke permission for SNS to the Lambda functions:

{
    "Type" : "AWS::Lambda::Permission",
    "Properties" : {
        "FunctionName" : { "Fn::GetAtt" : [ "YourLambda", "Arn" ] },
        "Action" : "lambda:InvokeFunction",
        "Principal" : "sns.amazonaws.com",
        "SourceArn" : { "Ref" : "YourSNSTopicArn" }
    }
}

Then you need to subscribe your Lambdas to your SNS topic. This can be done via API call or through CloudFormation.

{
    "Type" : "AWS::SNS::Topic",
    "Properties" : {
        "TopicName" : "YourTopicName",
        "Subscription" : [ {
            "Endpoint" : { "Fn::GetAtt" : [ "YourLambda", "Arn" ] },
            "Protocol": "lambda"
        } ]
    }
}

If you're missing any of this, your Lambdas won't invoke. Source for the above information is the official blog article Invoking Lambda functions via SNS.