问题
i am trying to add a message to queue in amazon aws sqs
so i tried this
root~# aws sqs send-message --queue-url "queue/url" --message-body "message with attribute" --message-attributes '{"Name": "somename", "Type":"String", "Value":"somevalue"}'
bit it gives me this error
'unicode' object has no attribute 'keys'
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"
then it works perfect
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)
回答1:
You need to pass --message-attributes (map) data structre like {attr1 : {"DataType":"type1.option", "StringValue":val1}, attr2 : {"DataType":"typ2.option", "StringValue":val2}, ...}
So your example becomes as follows:
sending queue
$ 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"
}
receiving queue
$ 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"
}
}
}
]
}
来源:https://stackoverflow.com/questions/25848003/map-datatype-in-aws-cli