AWS Lambda& SNS:调用Lambda跨区域 [英] AWS Lambda & SNS: Invoke Lambda cross-region

查看:150
本文介绍了AWS Lambda& SNS:调用Lambda跨区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Lambda函数部署到了多个区域.我想向SNS发布一条消息,这些消息将调用这些功能.

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

使用aws-cli,我已经创建了主题,并赋予Lambda与SNS对话的权限,并创建了订阅.订阅似乎已成功创建,并且可以在AWS控制台中看到它.但是,它不起作用. lambda函数不会被调用.

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.

推荐答案

这是基于CloudFormation的示例.您必须将SNS的调用权限添加到Lambda函数中:

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" }
    }
}

然后,您需要将Lambdas订阅到SNS主题.这可以通过API调用或通过CloudFormation来完成.

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"
        } ]
    }
}

如果您缺少任何一个,则不会调用您的Lambdas.以上信息的来源是官方博客文章调用Lambda通过SNS功能.

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.

这篇关于AWS Lambda& SNS:调用Lambda跨区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆