Setting Partition Key and Sort Key for DynamoDBv2 Table in AWS IoT Core

0

I have a IoT Node that is uploading data to AWS IoT Core.

I first created a DynamoDB table and selected the DynamoDB option in AWS IoT Core rules and have managed to get the Partition Key (PK) and Sort Key (SK) to work successfully along with forwarding data to a DynamoDB table.

However I wanted my data to be spread across columns in DynamoDB and not stored as a single column with a json packet, so I came across the DynamoDBV2 option in AWS IoT Core rules, and used that. I created a seperate table in DynamoDB this time with no PK and no SK and again, it worked perfectly.

Now I want the best of both worlds, I want to have a DynamodbV2 setup in AWS IoT Core, so my data is split across columns, but I also want to be able to set up a PK and SK. As it stands I don't see how this is possible in AWS IoT Core rules - when selecting DynamoDBV2 option there is no longer the ability to enter PK and SK values.

How can I have data sent from AWS IoT core to DynamoDB with data split across columns, while also setting a PK and SK (that is values from my uploaded packet). e.g. PK.= deviceID, SK = timestamp.

The only way I can imagine working around this is by creating an AWS IoT Core rule that runs a Lambda Script which does what I want above, however the preferred approach is to set it all up in AWS IoT Core.

vleppi
asked 4 months ago814 views
1 Answer
0

Under dynamoDBv2 rule the primary partion key and (optional) sort key is expected to be present in the MQTT message paylaod. "The MQTT message payload must contain a root-level key that matches the table's primary partition key and a root-level key that matches the table's primary sort key, if one is defined. which I guess is not the case..." So when creating your table you should define the primary and sort keys from the payload root-level key.

If deviceID and timestamp are part of your topic, you should be able to do what you are looking for.

If deviceID and timestamp are not set as root level topics -and you cannot modify the way the MQTT is being published-, you may need to perform DynamoDB putItem within a lambda function..

An alternative would be to republish (https://docs.aws.amazon.com/iot/latest/developerguide/republish-rule-action.html) the MQTT with modified topics so that they can be automatically processed by dynamoDBv2 rule.

AWS
Serge
answered 4 months 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