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


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:

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

asked 3 years ago108 views
1 Answer
Accepted Answer

Hi Taran,

The question was answered on (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.

answered 3 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