Shorthand syntax for message-attributes in the send-message command in aws-cli for sqs
Currently, the documentation of the short-hand syntax for the --message-attributes
option is incorrect and the short-hand syntax does not work.
Instead, you can use the JSON file (as you mentioned). You can also use the inline JSON:
aws sqs send-message
--queue-url https://sqs.us-east-1.amazonaws.com/0000000000/aa_queue_name
--message-body "message body goes here"
--message-attributes '{ "firstAttribute":{ "DataType":"String","StringValue":"hello world" }, "secondAttribute":{ "DataType":"String","StringValue":"goodbye world"} }'
Your Shorthand Syntax format is correct:
MY_KEY={DataType=String, StringValue=MY_VALUE}
You just forgot to enclose the commandline option with single or double quotes:
aws sqs send-message \
--queue-url https://sqs.us-east-1.amazonaws.com/0000000000/aa_queue_name \
--message-body "message body goes here" \
--message-attributes 'firstAttribute={DataType=String, StringValue="hello world"}, secondAttribute={DataType=String,StringValue="goodbye world"}'
The above shortcut syntax should correctly produce a message with 2 extra headers, a.k.a. Message Attributes:
firstAttribute=hello world
secondAttribute=goodbye world
NOTE:
an attribute is a <class 'dict'>
, so every attribute looks like a dictionary: {DataType=String, StringValue=MY_VALUE}
,
where supported
DataType
s are String, Number, and Binary.each DataType value can contain an optional custom extention, that is ignored by aws. For example: String.uuid, Number.int, Binary.pdf.
https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-attributes.html#message-attribute-components