使用AWS CLI向ElasticMQ本地SQS发送JSON消息报错,如何解决?
解决AWS CLI发送JSON消息体的zsh解析错误
出现zsh: parse error near '}'是因为zsh会将JSON中的{、}和空格当作shell语法解析,而非消息体的一部分。可以通过以下两种方式解决:
方法1:用单引号包裹JSON消息体
将整个JSON字符串用单引号包裹,单引号会阻止shell解析内部特殊字符,直接把完整JSON传递给AWS CLI:
aws --region=us-west-2 --endpoint=http://localhost:9324 sqs send-message --queue-url http://localhost:9324/000000000000/jobs --message-body '{"FileHashes": ["79054025255fb1a26e4bc422aef54eb4"] }'
方法2:通过文件传递JSON消息体
如果JSON内容复杂或较长,建议将其写入单独文件,再通过file://路径引用:
- 创建包含JSON内容的文件(例如
job-message.json):
{"FileHashes": ["79054025255fb1a26e4bc422aef54eb4"] }
- 执行AWS CLI命令引用该文件:
aws --region=us-west-2 --endpoint=http://localhost:9324 sqs send-message --queue-url http://localhost:9324/000000000000/jobs --message-body file://job-message.json
内容的提问来源于stack exchange,提问作者Anthony
相关产品推荐
相关产品推荐

