map datatype in aws cli

冷暖自知 提交于 2019-12-13 02:09:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!