AWS IoT DynamoDB rule not able to read value SELECTed from topic() function

0

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:

https://i.stack.imgur.com/gO9SG.png

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.

NB I've also posted this question to SO:https://stackoverflow.com/questions/59982125/aws-iot-dynamodb-rule-not-able-to-read-value-selected-from-topic-function

TaranS
asked 4 years ago531 views
1 Answer
0
Accepted Answer

Hi Taran,

The question was answered on https://stackoverflow.com/questions/59982125/aws-iot-dynamodb-rule-not-able-to-read-value-selected-from-topic-function (Kudos to Ben T.)

To paraphrase:
You cannot reference an alias (i.e. deviceName) created using the AS clause in Action substitution templates. However, you can use the same operations in the Action substitution templates - in this case ${topic(2)} for DDB partition key value.

AWS
answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions