使用 AWS CLI 命令添加 SQS 重新驱动策略 [英] Adding SQS redrive policy using AWS CLI command
问题描述
我正在尝试使用下面的 AWS CLI 命令为 SQS 设置重新驱动策略,但看到与重新驱动 JSON 相关的错误.你能告诉我如何解决这个问题吗?
I am trying to set redrive policy for SQS using the AWS CLI Command below , but seeing an error related to redrive JSON. Can you please let me know how I can fix this?
redrive_policy="{\"RedrivePolicy\":{\"deadLetterTargetArn\":\"$dlq_arn\",\"maxReceiveCount\":\"15\"}}"
AWS CLI 命令
aws sqs set-queue-attributes --queue-url https://queue.amazonaws.com/12345678/test-queue --attributes $redrive_policy --region=us-east-1
错误信息
参数验证失败:参数类型无效Attributes.RedrivePolicy, value: OrderedDict([(u'deadLetterTargetArn',u'arn:aws:sqs:us-east-1:12345678:dlq'), (u'maxReceiveCount', u'15')]),类型:,有效类型:
Parameter validation failed: Invalid type for parameter Attributes.RedrivePolicy, value: OrderedDict([(u'deadLetterTargetArn', u'arn:aws:sqs:us-east-1:12345678:dlq'), (u'maxReceiveCount', u'15')]), type: , valid types:
推荐答案
您是否尝试过在单独的文件中创建 JSON 并将其作为参数传递给您的 AWS CLI 命令?我发现将 JSON 作为参数传递时很难让所有转义都正确.因此,您基本上可以按照 AWS 文档中的示例进行操作:
Have you tried just creating the JSON in a separate file and passing it as an argument to your AWS CLI command? I find it's difficult to get all of the escaping correct when passing the JSON as a parameter. So you'd basically do it as the example shows in the AWS documentation:
https://docs.aws.amazon.com/cli/latest/reference/sqs/set-queue-attributes.html#examples
- 因此,首先您要创建一个名为set-queue-attributes.json"的新文件,如下所示:
{
"DelaySeconds": "10",
"MaximumMessageSize": "131072",
"MessageRetentionPeriod": "259200",
"ReceiveMessageWaitTimeSeconds": "20",
"RedrivePolicy": "{\"deadLetterTargetArn\":\"arn:aws:sqs:us-east-1:80398EXAMPLE:MyDeadLetterQueue\",\"maxReceiveCount\":\"1000\"}",
"VisibilityTimeout": "60"
}
- 然后像这样运行命令:
aws sqs set-queue-attributes --queue-url https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyNewQueue --attributes file://set-queue-attributes.json --region=us-east-1
这篇关于使用 AWS CLI 命令添加 SQS 重新驱动策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!