AWS Lambda &SNS:跨区域调用Lambda

编程入门 行业动态 更新时间:2024-10-28 11:32:15
本文介绍了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", "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 将不会被调用.以上信息来源为官方博客文章InvokingLambda 通过 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

本文发布于:2023-11-06 14:55:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564001.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Lambda   AWS   SNS   amp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!