CloudNext.Guru – AWS 7 – Storing IOT Data in a NoSQL DynamoDB Database



with AWS IOT you can build IOT solutions for virtually any use case across a wide range of devices log into AWS console search for IOT core on the welcome page click on get started in the left navigation pane choose manage to expand the choices and then choose things devices connected to AWS IOT are represented by things in the registry the registry allows you to keep a record of all of the devices that are connected to your AWS iot account choose register a thing choose create a single thing you type a name for your device such as my iOS button choose next to add your device to the registry keep everything as default and click Next communication between your vice and AWS IOT is protected through the use of X dot 509 certificates AWS IOT can generate a certificate for you or you can use your own x.509 certificate in this lab AWS IOT generates the x.509 certificate for you certificates must be activated prior to use choose create certificate on the certificate created page choose download certificate private key and the root CA for AWS IOT the public key need not be downloaded save each of them to your computer and then choose activate to continue click done and you will be redirected to the AWS IOT things root page bounine certificates are used to authenticate your device with AWS IOT AWS IOT policies are used to authorize your device to perform AWS IOT operations such as subscribing or publishing to mqtt topics your device presents its certificate when sending messages to AWS IOT to allow your device to perform AWS IOT operations you must create an AWS IOT policy and attach it to your device certificate to create an AWS iot policy in the left navigation pane choose secure and then policies and choose create a policy on the create a policy page in the name field type a name for the policy for example my I oat button policy in the action field type I connect in the resource AR n field type select the allow checkbox this allows all clients to connect to AWS IOT you created a policy you must attach it to your device certificate attaching an AWS iot policy to a certificate gives the device that permissions specified in the policy in the left navigation pane choose secure and then certificates in the box for the certificate you created choose dot-dot-dot to open a drop-down menu and then choose attach policy in the attach policies to certificates dialog box select the checkbox next to the policy you created in the previous step and then choose attach you a device must have a certificate private key Andrew certificate to authenticate with AWS IOT now you need to attach a certificate to the thing representing your device in the registry in the box for the you created choose dot-dot-dot to open a drop-down menu and then choose attach thing in the attached things to certificates dialog box select the checkbox next to the thing you registered and then choose attach to verify the thing is attached select the box representing the certificate on the details page for the certificate in the left navigation pane choose things five of policy is attached on the details page for the certificate in the left navigation pane choose policies now you can configure your device with the device certificate private key and root CA certificate in order to communicate with AWS ILP if you don't have the device you can use mqtt test client provided by AWS to simulate device interaction in the AWS iot console in the left navigation pane choose test subscribe to the topic on which our thing publishes in the case of the AWS IOT button you can subscribe to IOT button / + note that + is the wild-card character in subscribe to a topic in the subscription topic field type I out button / + and then choose subscribe to topic you choosing subscribe to topic above results in the topic I oat button / + appearing in the subscriptions column let's simulate the IRT button press on the mqtt client page in the publish section in the specify a topic and a message to publish field type I oat button SL 123456 in the message payload section type some sample jason that your device would send choose published a topic you should see the message in the AWS IOT MQTT client choose IOT button / + in the subscription column to see the message you publish more messages and view them now that we have the IOT device simulator ready let's try to save the data received from the device and a dynamo DB database dynamo DB is a no sequel database which is good for non-relational data its schema-less architecture allows for frequent changes to the database and easy addition of varied data to the system once the data is stored in the dynamo DB database it can be taken for further processing later on in the left navigation pane choose act which will take you to the AWS iot rules engine the AWS IOT rules engine listens for incoming mqtt messages that match a rule when a matching message is received the rule takes some action with the data in the mqtt message for example writing data to an Amazon s3 bucket invoking a lambda function sending a message to an Amazon SNS topic or storing the data into the dynamodb database which we are going to try now click create a rule create a rule called my dynamo diet rule Tech's like my IOT sensor data scroll down to rule query statement she was the latest version from the using sequel version drop-down list type the following query select from I out button SL 123456 click Add it action select insert a message into a dynamodb table click configure action click create a new resource this will take you to the dynamodb service page click create table give table name as Meowth button you at a primary key silen umber of type string you add a sort ki timestamp is type string click create it takes about ten seconds to create the table you you you can go under the items tab and see there is nothing in there currently back in the configure action page freshen select the newly created table you will see it Auto pop hashkee with a primary key serial number in the hash key value put the name of the field that your JSON file will be sending which is serial number note that s is small and serial number put it within braces dollar symbol and braces range key and populate the value with server timestamp using a pre-built function you you can add data sent by the button to bot tributes column where the data will be stored in JSON format you create a rule called mute button rule to give permission to IOT rule to insert data into DynamoDB you now publish to the topic and see the output in the DynamoDB table you you keep publishing using the test client and see the output getting stored in your table you thank you you

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *