如何使用Ansible和AWS向SNS订阅中添加重新驱动策略(死信队列/ DLQ)

在Ansible脚本中,我有:

- name: Subscribe lambda to snS topic example1
  sns_topic:
    name: "example1-{{env_name}}"
    purge_subscriptions: no
    subscriptions:
      - endpoint: "arn:aws:lambda:{{ aws.region }}:{{ aws.account }}:function:{{repo_name}}-{{env_name}}"
        protocol: "lambda"

它起作用了,结果是我的lambda订阅了我的snS主题。

现在,我想向此订阅添加DLQ。 我已经有一个SQS,我想将其声明为我的DLQ。

所以我这样重写我的代码:

- name: Subscribe lambda to snS topic example1
  sns_topic:
    name: "example1-{{env_name}}"
    purge_subscriptions: no
    subscriptions:
      - endpoint: "arn:aws:lambda:{{ aws.region }}:{{ aws.account }}:function:{{repo_name}}-{{env_name}}"
        protocol: "lambda"
        redrive_policy:
          dead_letter_target_arn: "arn:aws:{{ aws.region }}:{{ aws.account }}:dlq-for-example1"

这不起作用,我在Ansible中或通过谷歌搜索都找不到任何东西。

我在做什么错了?

yingcaiiacgniy 回答:如何使用Ansible和AWS向SNS订阅中添加重新驱动策略(死信队列/ DLQ)

好像您在最后一行的sqs之间缺少arn:aws:{{aws.region}}

dead_letter_target_arn: "arn:aws:sqs:{{ aws.region }}:{{ aws.account }}:dlq-for-example1"
,

问题在于,SNS主题中嵌入的“订阅”属性仅具有两个属性:“端点”和“协议”(请参见Subscription Property)。

对于更高级的设置,例如RedrivePolicy,您需要使用独立的 AWS :: SNS :: Subscription 资源(请参见Subscription Resource)。

由于AWS :: SNS :: Subscription是独立的,因此您必须包括Subscription绑定到的TopicArn。另外请注意,RedrivePolicy是Json格式。

这是Redrive Syntax中的Cloud Formation语法的简单示例:

{
  "Resources": {
    "mySubscription": {
      "Type" : "AWS::SNS::Subscription","Properties" : {
        "Protocol": "sqs","Endpoint": "arn:aws:sqs:us-east-2:123456789012:MyEndpoint","TopicArn": "arn:aws:sns:us-east-2:123456789012:MyTopic","RedrivePolicy": {
          "deadLetterTargetArn":
            "arn:aws:sqs:us-east-2:123456789012:MyDeadLetterQueue"
        }
      }
    }
  }
}

但是我不知道Ansible是如何进行这些翻译的。

本文链接:https://www.f2er.com/3050804.html

大家都在问