问题描述
我正在尝试添加一条消息以在亚马逊AWS sqs中排队
i am trying to add a message to queue in amazon aws sqs
所以我尝试了这个
root~# aws sqs send-message --queue-url "queue/url" --message-body "message with attribute" --message-attributes '{"Name": "somename", "Type":"String", "Value":"somevalue"}'
它给了我这个错误
'unicode' object has no attribute 'keys'
但是如果我从命令中删除了--message-attributes
部分
but if i remove the --message-attributes
part from the command
root~# aws sqs send-message --queue-url "queue/url" --message-body "message with attribute"
然后完美运行
http://docs.aws.amazon. com/cli/latest/reference/sqs/send-message.html
我想这是地图类型,如何以地图格式发送此参数
i guess that it is map type how can send this parameter in map format
--message-attributes (map)
推荐答案
您需要传递--message-attributes (map)
数据结构,如{attr1 : {"DataType":"type1.option", "StringValue":val1}, attr2 : {"DataType":"typ2.option", "StringValue":val2}, ...}
You need to pass --message-attributes (map)
data structre like {attr1 : {"DataType":"type1.option", "StringValue":val1}, attr2 : {"DataType":"typ2.option", "StringValue":val2}, ...}
因此您的示例如下:
$ aws sqs send-message --queue-url "queue/url" --message-body "message with attribute" --message-attributes '{"somename" : { "DataType":"String", "StringValue":"somevalue"}}'
{
"MD5OfMessageBody": "ZZZZ",
"MD5OfMessageAttributes": "YYYY",
"MessageId": "06524772-XXXX"
}
接收队列
$ aws sqs receive-message --queue-url "queue/url" --message-attribute-names somename
{
"Messages": [
{
"Body": "message with attribute",
"ReceiptHandle": "dummy==",
"MD5OfBody": "ZZZZ",
"MD5OfMessageAttributes": "YYYYS",
"MessageId": "06524772-XXXX",
"MessageAttributes": {
"somename": {
"DataType": "String",
"StringValue": "somevalue"
}
}
}
]
}
这篇关于AWS CLI中的地图数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!