我正在尝试编写一个跨帐户 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\"]}'}"
运行此程序时出现以下错误。
Unknown options: --attributes, [\value1\,, \value2\]}'}, {'RawMessageDelivery': 'true', 'FilterPolicy': '{" filter\:
我可以访问两个 aws 帐户的管理员访问权限。关于我做错了什么的任何建议?
编辑:
我在 Windows 的 VS Code powershell 终端中运行它。
最佳答案
可能有一种更简单的方法来做到这一点(例如使用 --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\\\"]}\"}'
问题是包含在字符串中的 JSON,它需要 \"
被转义为 \\\"
.
关于amazon-web-services - aws cli 命令订阅带有过滤器的主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61258614/