By the end of this chapter, your serverless application should do the following:
Up until this point, every aspect of your IoT solution has been ephemeral in the sense that each message is received, processed, and then discarded. In the case of the IoT Events detector model, there is a stateful entity that reacts to new messages, but otherwise there is no stored history of your thermostat messages. This is the step that establishes a data store for your thermostat messages.
AWS offers many ways to store data in the cloud, and storing IoT data is no different. This solution advocates the use of a service called AWS IoT Analytics, which is a managed service purpose built to receive, store, process, and analyze IoT data in bulk. You will use IoT Analytics to store a subset of each update to the device shadow.
The AWS IoT Analytics documentation covers this in more detail, but here is a brief summary of how it works. The entry point to the service is a resource called a channel. A channel stores all the raw data for your workflow. It also sends a copy of each message received to the next resource, called a pipeline. A pipeline is a series of activities to process, cleanse, filter, and enrich data before it is used in analytics use cases. The processed messages are put from the pipeline into a data store. A data store, like a channel, is a long-lived storage unit for processed data. Finally, a data set is the last resource in the AWS IoT Analytics project. A data set defines a SQL-like query that can read messages out of a data store as a materialized view and deliver the contents of the query to a destination like an S3 bucket.
Your smart space solution will accumulate multiple hours of runtime data from your thermostat in AWS IoT Analytics. After that, the result of a data set query will make this data available for use in our machine learning toolchain provided by Amazon SageMaker.
There is much, much more to AWS IoT Analytics but for the purposes of this module it is the easiest way to store the history of our thermostat messages and aggregate them as a training data set for our machine learning model.
Leaving this application running beyond 6 hours can result in AWS charges. It is recommended you finish this tutorial in that time and perform the cleanup steps to avoid any unwanted costs.
The following steps detail how to create a new IoT Core rule, a new AWS IoT Analytics project, and uses the rule to forward device shadow messages to your AWS IoT Analytics project. There’s a handy interface in the IoT Core rule creation wizard for creating the entire AWS IoT Analytics project on your behalf!
SELECT current.state.reported.sound, current.state.reported.temperature, current.state.reported.hvacStatus, current.state.reported.roomOccupancy, timestamp FROM '$aws/things/<<CLIENT_ID>>/shadow/update/documents'
smartspace. Choose Quick Create and all your AWS IoT Analytics resources will be created and configured automatically.
Before moving on to the next chapter, you can validate that your serverless application is configured as intended by…
If these are working as expected, let’s move on to Machine learning.