Close

AWS DynamoDB interfaced with IoT Core

A project log for FIMble

Concept of a plug-and-play IoT food monitoring system. It aims to reduce food wastage at consumer and distributor level

zst123zst123 06/27/2020 at 13:170 Comments

Before we start, I did some research on Amazon FreeRTOS and how Amazon IoT/MQTT works

I previously confirmed that MQTT messages are sent successfully with the demo code. From the AWS website, we can monitor it too:


Since my application is to do inventory tracking, I will need to use my IoT device to update a database.

In AWS, I see that I can do this from IoT core -> Lambda -> DynamoDB. I followed this guide.

Connect IoT core to Lambda using IoT Rules.

Go to Act > Rule > Create a rule.

I used this query string SELECT * FROM '#'

Go to Add Action > Send a message to a Lambda function > Create a new Lambda function > Select your function > Create rule.


In order for AWS IoT to call a Lambda function, you must configure a policy granting the lambda:InvokeFunction permission to AWS IoT.

But when I run this command I get an error

To solve this, find your user in the IAM management console > Permissions > Add inline policies. Use these settings:

Now when I run the command again, it works.


From lambda, when I used the “Test” button in Lambda, I got another “AccessDeniedException”. 

From lambda to dynamodb, we also need to add permissions. I solved this by adding “AmazonDynamoDBFullAccess” permission.

Go to your IAM console > Access management > Roles

Find the role for your lambda. When I created mine, I left it as the the default name so it is Handler-role-0cwysi5m.

Go to Permissions > Attach policies, and find  “AmazonDynamoDBFullAccess”.

After this, I can successfully write to DynamoDB

Discussions