amazon-web-services - aws cli 命令订阅带有过滤器的主题

标签 amazon-web-services powershell amazon-sqs publish-subscribe 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\"]}'}"

运行此程序时出现以下错误。
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/

相关文章:

amazon-web-services - CIDR block 格式错误。这个 CLI 命令有什么问题?

c# - 在 C# 应用程序中运行 PowerShell 进程并与之交互

amazon-web-services - Amazon SNS 和 Amazon SQS 有什么区别?

powershell - 简单的PowerShell选择字符串模式

windows - 如何在运行批处理脚本时获取当前事件窗口?

node.js - 发送消息时AWS SQS "ECONNREFUSED"

amazon-sqs - 为什么 SQS 中的 ApproximateAgeOfOldestMessage 不大于约 5 分钟

amazon-web-services - eu-西-1 AWS 'Could not fetch tags: An internal error has occurred'

amazon-web-services - 属性 Id 的值必须为字符串类型 - CloudFormation 模板中出现错误

amazon-web-services - 从控制台从 Elastic Beanstalk 实例之一获取公共(public) DNS