简体   繁体   English

如何使用 cloudformation/SAM 创建一个 SQS 队列,该队列与使用 SAM 创建的 lambda 一起使用?

[英]How to create an SQS queue with cloudformation/SAM that works with lambdas created with SAM?

I am creating lambdas from the AWS SAM, mostly they are working well but I am not sure how to grant permission for these lambda's to be triggered by SQS.我正在从 AWS SAM 创建 lambda,大多数情况下它们运行良好,但我不确定如何授予 SQS 触发这些 lambda 的权限。 Whenever I build/package/deploy I am trying to manually add an SQS trigger from the console and I get the following error:每当我构建/打包/部署时,我都会尝试从控制台手动添加 SQS 触发器,但出现以下错误:

An error occurred when creating the trigger: The provided execution role does not have permissions to call ReceiveMessage on SQS (Service: AWSLambda; Status Code: 400; Error Code: InvalidParameterValueException

I fully realize that it would be ideal to create the SQS with SAM as well, however I can't find decent guides, specifically about how to build yaml files for deploying with.我完全意识到用 SAM 创建 SQS 也是理想的,但是我找不到像样的指南,特别是关于如何构建用于部署的 yaml 文件。 I wondered if this error meant I need to add a policy to the template.yaml before the build/package/deploy.我想知道这个错误是否意味着我需要在 build/package/deploy 之前向 template.yaml 添加一个策略。 So I added the following policies to the yaml under Resources:MyFunction:Properties:policies:所以我在Resources:MyFunction:Properties:policies下的yaml中添加了以下策略:

- SQSSendMessagePolicy:
    QueueName: "*"
- SQSPollerPolicy:
    QueueName: "*"

I got these from here but I can't see a 'receive message from SQS' policy, I'm unsure where else to get one?我从这里得到了这些,但我看不到“从 SQS 接收消息”政策,我不确定还能从哪里得到? Or if this is even the problem?或者如果这甚至是问题?

I also tried to add the following to the yaml:我还尝试将以下内容添加到 yaml:

  Events:
    MySQSEvent:
      Type: SQS
      Properties:
        Queue: 
          !GetAtt arn:aws:sqs:eu-west-1:my_arn.my_queue
        BatchSize: 10

However this gives me the following error when I try to deploy:但是,当我尝试部署时,这给了我以下错误:

Template error: instance of Fn::GetAtt references undefined resource arn:aws:cloudformation:eu-west-1:my_arn

I have tried looking around for a guide to set up SQS through cloudformation but decent guides seem very elusive.我曾尝试四处寻找通过 cloudformation 设置 SQS 的指南,但体面的指南似乎非常难以捉摸。 The ones that are around seem overly verbose and complicated making them unsuitable for new users.周围的那些看起来过于冗长和复杂,使它们不适合新用户。

All I want to achieve is pass a list of events to an SQS (perhaps with a lambda) which will then queue another lambda to receive those events in batches of 10 (around 20,000 total).我想要实现的只是将事件列表传递给 SQS(可能带有 lambda),然后将另一个 lambda 排队以分批 10 个(总共大约 20,000 个)接收这些事件。 I need to be able to do this with SAM is the only caveat.我需要能够用 SAM 做到这一点是唯一的警告。 I appreciate making lambdas on the console would make this a great deal easier but its not appropriate for version control.我很欣赏在控制台上制作 lambdas 会使这更容易,但它不适合版本控制。

So far I have looked at the following and can't see an obvious solution, the information seems not quite right to apply to my use case;到目前为止,我已经查看了以下内容,但没有看到明显的解决方案,这些信息似乎不太适合我的用例; SO question 1 , SO question 2 , aws alter stack tutorial , aws cloudformation templates , dzone tutorial , aws docs . SO 问题 1SO 问题 2aws 更改堆栈教程aws cloudformation 模板dzone 教程aws 文档

Would really appreciate any pointers/help/how-to-guides/full working solutions?真的很感激任何指示/帮助/操作指南/完整的工作解决方案吗?

Many thanks非常感谢

Your Events part should be like this你的活动部分应该是这样的

Events:
MySQSEvent:
  Type: SQS
  Properties:
    Queue: !GetAtt QUEUE_NAME.Arn

Where QUEUE_NAME is the logical name of your SQS Queue in the Cloud Formation template其中 QUEUE_NAME 是 Cloud Formation 模板中 SQS 队列的逻辑名称

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

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