【问题标题】:AWS SAM: Use an existing SQS Queue in templateAWS SAM:在模板中使用现有的 SQS 队列
【发布时间】:2020-07-18 20:10:58
【问题描述】:

我有一个 lambda 函数,它应该在消息到达我的队列时触发。我正在通过 SAM cli 开发和部署此功能。但是,SQS 队列已经存在,由于我的用例的限制,我无法将它与 lambda 函数一起创建。所以,我必须使用这个现有的队列。

下面是我的template.yml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  Serverless functions for foobar


Globals:
  Function:
    Timeout: 60 # 60 seconds timeout for each lambda function

Resources:

  # Lambda function #1; foobar SQS trigger
  OrderDrop:
    Type: AWS::Serverless::Function 
    Properties:
      CodeUri: sqs_trigger/foobar
      Handler: app.lambda_handler
      Runtime: python3.8
      Description: foobar SQS trigger
      Events:
        FooBarSQS:
          Type: SQS
          Properties:
            Queue: !GetAtt FooBarSQS.Arn
            BatchSize: 1

  # Foobar SQS
  FooBarSQS:
    Type: SQS
    Properties:
      Queue: arn:aws:sqs:us-east-1:1234567890:foobar_queue.fifo
      Enabled: true

我收到以下错误:

错误:无法为堆栈创建变更集:gitlabpoc,例如:Waiter ChangeSetCreateComplete failed:Waiter 遇到终端故障状态状态:FAILED。原因:模板格式错误:无法识别的资源类型:[SQS]

我一直在关注这份文件:

https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-sqs.html

还有这个文件:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-queues.html

但我无法告诉我现有队列的 arn

我怎样才能做到这一点?

【问题讨论】:

    标签: amazon-web-services aws-lambda amazon-sqs aws-sam


    【解决方案1】:

    我想通了,因为我的 OrderDropEvent 中的 Queue: !GetAtt FooBarSQS.Arn 属性需要队列 arn,我只是给了它现有队列的 arn。

    OrderDrop:
        Type: AWS::Serverless::Function 
        Properties:
          CodeUri: sqs_trigger/foobar
          Handler: app.lambda_handler
          Runtime: python3.8
          Description: foobar SQS trigger
          Events:
            FooBarSQS:
              Type: SQS
              Properties:
                Queue: arn:aws:sqs:us-east-1:1234567890:foobar_queue.fifo
                BatchSize: 1
    

    这成功了!

    【讨论】:

      猜你喜欢
      • 2019-04-03
      • 2020-08-11
      • 1970-01-01
      • 1970-01-01
      • 2019-11-15
      • 2021-04-24
      • 2019-09-23
      • 2021-01-07
      • 1970-01-01
      相关资源
      最近更新 更多