AWS Lambda & SNS: Invoke Lambda cross-region

后端 未结 1 917
感动是毒
感动是毒 2021-01-12 19:59

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 top

相关标签:
1条回答
  • 2021-01-12 20:08

    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.

    0 讨论(0)
提交回复
热议问题