简体   繁体   English

AWS Lambda&SNS:调用Lambda跨区域

[英]AWS Lambda & SNS: Invoke Lambda cross-region

I have a Lambda function deployed to several regions. 我有一个Lambda函数部署到几个地区。 I would like to publish a message to SNS that will invoke these functions. 我想向SNS发布一条消息来调用这些函数。

Using aws-cli I've created the topics, given Lambda permission to talk to SNS, and create the subscriptions. 使用aws-cli我创建了主题,给予了与SNS通信的Lambda权限,并创建了订阅。 The subscription appears to be created successfully, and I can see it in the AWS console. 订阅似乎已成功创建,我可以在AWS控制台中看到它。 But, it doesn't work. 但是,它不起作用。 The lambda function does not get invoked. lambda函数不会被调用。

This is CloudFormation based example. 这是基于CloudFormation的示例。 You have to add invoke permission for SNS to the Lambda functions: 您必须将SNS调用权限添加到Lambda函数:

{
    "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. 然后,您需要将您的Lambdas订阅到您的SNS主题。 This can be done via API call or through CloudFormation . 这可以通过API调用或通过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. 如果您遗漏了任何此类内容,您的Lambdas将不会调用。 Source for the above information is the official blog article Invoking Lambda functions via SNS . 以上信息的来源是官方博客文章通过SNS调用Lambda函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM