aws cli 命令使用过滤器订阅主题

use*_*007 1 powershell publish-subscribe amazon-sqs amazon-web-services amazon-sns

我正在尝试编写一个跨帐户 aws cli 命令来订阅主题并同时为该订阅创建过滤器。下面是我的命令的样子。

aws sns subscribe --topic-arn arn:aws:sns:region:accountId:my_topic --protocol sqs --notification-endpoint arn:aws:sqs:region:differentAccountId:my_sqs_queue --attributes "{'RawMessageDelivery': 'true', 'FilterPolicy': '{\"filter\": [\"value1\", \"value2\"]}'}"
Run Code Online (Sandbox Code Playgroud)

运行此程序时出现以下错误。

Unknown options: --attributes, [\value1\,, \value2\]}'}, {'RawMessageDelivery': 'true', 'FilterPolicy': '{" filter\:
Run Code Online (Sandbox Code Playgroud)

我可以访问两个 aws 帐户的管理员访问权限。关于我做错了什么的任何建议?

编辑: 我在 Windows 的 VS Code powershell 终端中运行它。

Joh*_*ein 11

可能有一种更简单的方法来做到这一点(例如--cli-input-json在文件中使用和提供 JSON),但我得到了这个工作:

aws sns subscribe \
  --topic-arn arn:aws:sns:region:accountId:my_topic \
  --protocol sqs \
  --notification-endpoint arn:aws:sqs:region:differentAccountId:my_sqs_queue \
  --attributes '{\"RawMessageDelivery\": \"true\", \"FilterPolicy\": \"{\\\"filter\\\": [\\\"value1\\\", \\\"value2\\\"]}\"}'
Run Code Online (Sandbox Code Playgroud)

问题是包含在字符串中的 JSON,需要\"将其转义为\\\".

  • 谢谢你。文档很糟糕。我不需要太多转义... `--attributes '{"FilterPolicy":"{\"filter\":[\"value1\",\"value2\"]}"}'` (4认同)