How to use the MessageAttribute parameter in aws sqs

Hi,

I’m trying to add the humidity and temperature values that I read from the device as a MessageAttribute (along with other data that I send).
When I send the data without the MessageAttribute, it delivered fine. But when I add the MessageAttribute to the sendParams, the data is not transferred (probably I do not use it right).

This is how I try using it:
// SQS send message parameters
local sendParams = {
“QueueUrl” : “URL”,
“MessageGroupId” : format("%s",theDeviceID),
“MessageBody” : Data,
“MessageAttribute.1.Name” : “Temperature”,
“MessageAttribute.2.Name” : “Humidity”,
“MessageAttribute.1.Value” : Temperature,
“MessageAttribute.2.Value” : Humidity,
“MessageAttribute.1.Type” : “String”,
“MessageAttribute.2.Type” : “String”,
“MessageDeduplicationId” : id
};

I’m not totally sure how these attributes are handled; I don’t see any special handling in the (10 line) SQS library that seems to deal with MD5 of the attributes as detailed here: Message metadata - Amazon Simple Queue Service

Amazon’s docs assume you’re using an amazon provided library, so aren’t actually much use when it comes to formatting the JSON you’re posting.

However, one thing I did notice is that you’re saying the type is “string” for both attributes, and (quite possibly, but I can’t see without having visibility into more of your code) that you’re putting numbers in there vs strings.

Like, if you added “.tostring()” after your Temperature and Humidity parameters, does it work? (AWS docs imply that EVERYTHING must be a string, even if you say the type is “Number”)

This topic was automatically closed after 60 days. New replies are no longer allowed.