Before you begin, prepare the weather station emulator and connect it to AWS IoT Core by completing this Learning Path .
Start by creating the rule:
SELECT * FROM 'Emulators/Weather/SensorReadings'
In the Create rule view, click the Refresh button next to the Choose DynamoDB table name drop-down. Then, select the SensorReadings table from that drop-down. Afterward, click the Create new role button (located below the IAM role). This activates the Create role pop-up.
In the Create role pop-up window, type ‘weather_station_dynamo_db’, and click the Create button. By now, the Attach rule actions screen looks like this:
Now, everything is set up. The messages sent from the device are automatically inserted as new rows into the SensorReadings table. To check this, run the application from Create IoT applications with Windows on Arm and AWS IoT Core . Namely, open the command prompt, change the working directory to AWS.WeatherStation, and then type:
npm start
This starts the emulator, which streams data to the AWS IoT Core. The output of the emulator looks like this:
{"deviceId":"WeatherStationEmulator","timestamp":"2024-05-03T10:40:51.239Z","temperature":"22.35","humidity":"58","pressure":"1000.1"}
{"deviceId":"WeatherStationEmulator","timestamp":"2024-05-03T10:40:52.274Z","temperature":"27.59","humidity":"54","pressure":"1006.1"}
{"deviceId":"WeatherStationEmulator","timestamp":"2024-05-03T10:40:53.296Z","temperature":"38.77","humidity":"52","pressure":"1019.6"}
{"deviceId":"WeatherStationEmulator","timestamp":"2024-05-03T10:40:54.305Z","temperature":"32.57","humidity":"54","pressure":"1020.8"}
{"deviceId":"WeatherStationEmulator","timestamp":"2024-05-03T10:40:55.305Z","temperature":"30.86","humidity":"53","pressure":"1014.9"}
To ensure this data is written to the DynamoDB table, go to the AWS console, and in the search box type ‘DynamoDB’. Select DynamoDB from the list. This takes you to the DynamoDB dashboard, where you click Explore items on the left. Then, check the SensorReadings radio button, and you see the items in the table:
Note that the values in the table are the same as those generated by the emulator. This ensures that you have successfully integrated AWS IoT Core with DynamoDB.
In this learning path, you learned how to use the Rules Engine to write data from the weather station emulator to DynamoDB. This process involved creating a database in Amazon DynamoDB and using the Rules Engine to establish rules that automatically transfer the data to a DynamoDB table. Through these steps, you gained practical experience in managing real-time IoT data workflows and enhancing the scalability and responsiveness of IoT applications.