I'm trying to get data from an AWS IoT MQTT topic into DynamoDB using a rule.
An example topic is cooler/cooler42/sensors
and example message
{
"waterTemp": 10,
"timestamp": 1580370731383
}
I've defined the query like so, to extract the deviceName
(e.g. cooler42
) from the topic and insert it into the JSON:
SELECT *, topic(2) AS deviceName FROM 'cooler/+/sensors'
This does indeed seem to work, as if I republish the message to another topic I now see the same JSON with deviceName
added:
{
"waterTemp": 10,
"timestamp": 1580370731383,
"deviceName": "cooler42"
}
My understanding is that all 3 fields should now be available for use within my DynamoDB rule like so:
However I can see from CloudWatch that the rule is failing with error
One or more parameter values were invalid: An AttributeValue may not contain an empty string (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException
and the partition key (aka hash key) is coming through as empty:
{
"ItemRangeKeyValue":"1580370731383",
"IsPayloadJSON":"true",
"ItemHashKeyField":"deviceName",
"Operation":"Insert",
"ItemRangeKeyField":"timestamp",
"Table":"SensorDataTest2",
"ItemHashKeyValue":"" <--- Empty
}
Am I not able to use the deviceName
I've just SELECTed from the topic name in the rule? If not is there another way to extract it?
NB If I manually publish a message onto the topic already including the deviceName
then it does work fine, but I'm working in a constrained environment and don't want the extra payload size.