Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shorthand syntax for message-attributes in the send-message command in aws-cli for sqs

When trying to send a message using AWS CLI for SQS, I cannot get the shorthand syntax for the --message-attributes parameter to work.

Specifying a json file works fine, and the reference doesn't show an example for the shorthand option.

Here is the reference for this command which specifies the shorthand I'm trying to use but I can't get it to work: http://docs.aws.amazon.com/cli/latest/reference/sqs/send-message.html

Here's the command I've tried:

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"}

I keep getting error messages:

Parameter validation failed: Invalid type for parameter MessageAttributes.contentType, value: StringValue=Snapshot, type: , valid types:

Anyone ever managed sending attributes for message using the shorthand?

like image 544
alifib Avatar asked Sep 07 '16 13:09

alifib


2 Answers

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"} }'
like image 151
Matt Houser Avatar answered Sep 19 '22 01:09

Matt Houser


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 DataTypes 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

like image 44
epox Avatar answered Sep 19 '22 01:09

epox