CloudFormation SQS Queue Redrive 策略依赖于创建的 DLQ

CloudFormation SQS Queue Redrive policy dependency on a DLQ created

我正在使用 CloudFormation 模板为 SQS 创建堆栈。我有一个 SQS 队列集,它依赖于另一个用作 DLQ 的 SQS 队列。当我创建堆栈时出现此错误:

Value {"deadLetterTargetArn":"arn:aws:sqs:eu-west-1:xxxxxxxxx:services-abc-dlq","maxReceiveCount":"10"} for parameter RedrivePolicy is invalid. Reason: Dead letter target does not exist.

如何设置重新驱动策略以等待 DLQ 创建完成?

这是我模板中的相关信息:

"Resources": {
    "queueservicesdlqevents": {
      "Type": "AWS::SQS::Queue",
      "Properties": {
        "DelaySeconds": "0",
        "MaximumMessageSize": "262144",
        "MessageRetentionPeriod": "345600",
        "QueueName": "services-abc-dlq",
        "ReceiveMessageWaitTimeSeconds": "0",
        "VisibilityTimeout": "30"
      }
    },
    "queueservicesevents": {
      "Type": "AWS::SQS::Queue",
      "Properties": {
        "DelaySeconds": "0",
        "MaximumMessageSize": "262144",
        "MessageRetentionPeriod": "345600",
        "QueueName": "services-abc-events",
        "ReceiveMessageWaitTimeSeconds": "20",
        "VisibilityTimeout": "30",
        "RedrivePolicy": {
          "deadLetterTargetArn" : "arn:aws:sqs:eu-west-1:xxxxxx:services-abc-dlq",
          "maxReceiveCount" : 10
        }
      }
    },

补充一下,将 "Ref" 发送到其他队列是行不通的,因为 dlqtargetArn 需要一个字符串。

Just to add, making a "Ref" to other queue doesn't work because dlqtargetArn expects a string.

Ref only provides the (default) value of an AWS CloudFormation resource, but you can get the value of other attributes of a resource by means of Fn::GetAtt如下:

"Fn::GetAtt" : [ "logicalNameOfResource", "attributeName" ]

也就是说,根据 Return 部分 AWS::SQS::Queue 中的值 ,手头的死信队列的 ARN 可通过以下方式获得:

"Fn::GetAtt" : [ "queueservicesdlqevents", "Arn" ]

从依赖资源引用实际 ARN 后,CloudFormation 将确保首先创建依赖关系,以便在创建 queueservicesevents 队列时死信目标 queueservicesdlqevents 已经存在。