-1

I am newbie on AWS side working on a AWS IOT project where all devices updates there state and send a json to the AWS IOT.A rule is there to save data to dynamodb.I have created a table in dynamodb. I am sending below data to the AWS,

{
  "state": {
  "reported": {
      "color": "Blue",
 "mac":"123:123"
  }
 }
}

But on Dynamodb it is saving three items ,first for state another for current and one for metadata. I want to save only data which is coming for state.Is there any condition I have to write for this.

Harshal Bulsara
  • 7,898
  • 4
  • 43
  • 61
Ashish Kumar Verma
  • 1,322
  • 1
  • 13
  • 21
  • how do you want it to be saved on DynamoDB? – Amit Kumar Ghosh Jul 05 '16 at 07:27
  • Right now,I got three items are saved in db ,one with payload starting with "state" another with "current" and third one with "metadata". I want only payload with state stores in db. – Ashish Kumar Verma Jul 05 '16 at 07:32
  • can you explain the table structure you need? – Amit Kumar Ghosh Jul 05 '16 at 07:33
  • I am sending mqtt data as described above And on db side I got three items which are 1.`{ "key": "things", "payload": { "state": { "reported": { "color": "Blue", "mac": "123:123" } } }, "timestamp": "1467700865704" }` – Ashish Kumar Verma Jul 05 '16 at 07:36
  • Second element is 2.`{ "key": "things", "payload": { "metadata": { "reported": { "color": { "timestamp": 1467700865 }, "mac": { "timestamp": 1467700865 } } }, "state": { "reported": { "color": "Blue", "mac": "123:123" } }, "timestamp": 1467700865, "version": 1 }, "timestamp": "1467700865720" }` – Ashish Kumar Verma Jul 05 '16 at 07:38

1 Answers1

-1

Instead of creating a rule to write directly to DynamoDB, which IMHO, is not a good practice, have the rule trigger a Lambda function, which then processes the payload ( maybe even does some error checking ) and writes to DynamoDB.

I don't believe there is any way to configure how you want the data mapped to DynamoDB so you need something like lambda to map it.

Longer term, if you need to change your schema ( or even change the database ), you can change the lambda to do something else.

dkarchmer
  • 5,434
  • 4
  • 24
  • 37
  • 1
    Writing directly to DynamoDB is best practice, and ONLY practice when designing Serverless to scale. API Gateway supports mapping the data. – sudo soul Feb 21 '18 at 05:19
  • @sudosoul did you read the OP? This is an IOT question. Not API gateway. – dkarchmer Feb 21 '18 at 06:32