The Internet of Things on AWS – Official Blog
Patterns for rapid IoT solution prototyping using AWS IoT Greengrass and Docker
Introduction
Research suggests that Internet of Things (IoT) solution implementations typically take an average of 18-24 months to reach the market and be ready for adoption. Common scenarios related to IoT solution development include device provisioning, telemetry collection, and remote command and control. Depending on your use case, prototyping a well-architected IoT solution requires considerations for good design principles and best practices for each of these scenarios. This post illustrates how you can adopt a prototyping design pattern that combines an AWS Cloud Development Kit (AWS CDK), AWS IoT Greengrass, and Docker to accelerate your IoT solution prototyping on AWS.
AWS CDK accelerates cloud development using the expressive power of common programming languages to model your cloud resources on AWS. IoT Greengrass is an open-source edge runtime and managed cloud service for building, deploying, and managing device software. You can use this runtime to run your workloads at the edge, deploy new or legacy applications across your IoT device fleets, and manage and operate your device fleets remotely. The runtime also has over 30 AWS pre-built components helping you to extend edge device functionality without writing custom code.
IoT Greengrass supports a variety of deployment methods, including running inside of or as a Docker container. You can combine codified infrastructure patterns created using AWS CDK with containerization and automation to create a consistent approach to testing or investigating IoT device functionality. This approach supports rapid IoT solution prototyping without leaving behind non-critical interim artifacts during prototyping iterations.
Solution overview
This post illustrates this approach supports common IoT solution scenarios, namely – device provisioning, device command and control, and telemetry collection.
Device provisioning
Secure IoT device provisioning requires configuring devices with unique identities, registering these identities with the AWS IoT service, and associating required permissions so that devices can securely connect and interact with AWS IoT and other required AWS services. This requirement applies to setting up an IoT Greengrass Core device. The following steps show how to provision an IoT Greengrass core device:
- Create an AWS IoT Core policy.
- Create an AWS IoT thing, group, certificate, and private key.
- Create an AWS IoT role alias and an AWS Identity and Access Management (IAM) role.
- Setup the IoT Greengrass Core device.
- Deploy IoT Greengrass component(s) for prototyping and testing.
To streamline the steps above, adopt the pattern as shown in Figure 1. This pattern uses the AWS CDK and Docker to simplify and streamline the creation of all supporting resources so you can focus on building differentiated functionality for your IoT solution. This pattern includes the following elements:
- An AWS CDK stack to represent required AWS resources as reusable constructs. AWS resources are deployed through AWS CDK CLI using AWS CloudFormation.
- A helper script that downloads the newly created AWS IoT client certificate, and configures a Docker Compose file and an IoT Greengrass setup script.
- A Docker container that sets up the IoT Greengrass Core device and deploys the AWS-provided components and any optional custom components.
Expand this section for more information about Figure 1
The figure demonstrates the steps to automate creating and deploying resources for a complete IoT Greengrass core device. Using AWS CDK (1) and CloudFormation (2), create the required AWS IoT and IAM resources. Use the supplied helper script (3) to finalize local configuration and launch IoT Greengrass in a local Docker container (4).
You can create a functional IoT Greengrass core deployment using a combination of AWS IoT services, infrastructure deployment, and Docker. Afterward, proceed with the specialized component development as required for your solution.
Remote Management and Command and Control
Another common scenario you may encounter when building IoT solutions is the ability to interact with your IoT devices remotely. For example, requesting specific telemetry data from a piece of industrial equipment, or scheduling home automation events. Following AWS best practices, use the bi-directional capability of the MQTT protocol. To support this, AWS provides the Device Shadow and AWS IoT Jobs to implement command and control over MQTT.
Building on top of the pattern described in Figure 1, you can expand the approach to quickly enable device command and control functionality over MQTT. An example of this pattern is shown in Figure 2. This pattern includes:
- An AWS CDK stack that:
- Creates additional AWS IoT Core and IAM policies.
- Creates a new AWS IoT thing group.
- Adds the existing AWS IoT thing to the new group.
- Deploys a custom IoT Greengrass component for device command and control.
- Deploys resources using the AWS CDK CLI using CloudFormation.
This pattern uses AWS CDK runtime context to reference the supporting AWS CDK resources from the base CloudFormation stack created before. This pattern focuses on creating and testing out new features without the need to reimplement or redeploy those resources.
Once the stack is successfully deployed, the custom component subscribes to the specified MQTT topic and listens to incoming command requests. Issue commands to the device through this topic and receive completion status messages in the response MQTT topic.
You can adopt this approach to rapidly prototype custom device command and control functionality as part of your AWS IoT solution to support your use case.
Expand this section for more information about Figure 2
Using AWS CDK (1), reference the previously deployed base CloudFormation stack (2), create additional AWS IoT, IAM, and IoT Greengrass deployment resources. The MQTT-based command and control component is deployed to the IoT Greengrass core device running locally.
Telemetry collection
Finally, a typical IoT solution requires functionality to collect telemetry data from physical assets, sensors, or pieces of industrial equipment. Collected data can support many IoT applications, such as streaming analytics, digital twins, predictive maintenance, and process simulation and optimization. For more information, see Seven patterns for IoT data ingestion and visualization.
Using the base device provisioning pattern as a foundation (Figure 1), you can explore options to ingest IoT data into AWS to satisfy your use case requirements. For example, use AWS IoT SiteWise running on an IoT Greengrass Core device to collect, organize, and analyze data from industrial equipment at scale. Specifically, create a solution to ingest industrial telemetry data using the OPC-UA protocol. Once ingested, the data can be visualized and analyzed to respond to anomalies or identify differences across industrial facilities.
To implement this solution, adopt the pattern shown in Figure 3. As with the earlier patterns, this pattern includes:
- An AWS CDK stack that:
- Creates dedicated AWS IoT Core and IAM policies.
- Creates a new AWS IoT thing group.
- Adds the existing AWS IoT thing to the new group.
- Deploys the necessary IoT Greengrass components (AWS IoT SiteWise OPC-UA collector, AWS IoT SiteWise publisher, and IoT Greengrass stream manager).
- Deploys resources using the AWS CDK CLI using CloudFormation.
This pattern also uses AWS CDK runtime context to reference the supporting AWS CDK resources from the base AWS CloudFormation stack created previously.
Once deployed, your IoT Greengrass Core device will be able to collect telemetry from an existing OPC-UA endpoint and publish this telemetry to AWS IoT SiteWise. For more information, see Ingesting data to AWS IoT SiteWise.
Expand this section for more information about Figure 3
Using AWS CDK (1), reference the previously deployed base CloudFormation stack (2), create additional AWS IoT, IAM, and IoT Greengrass deployment resources. The required AWS IoT SiteWise components for telemetry collection and publishing are deployed to the IoT Greengrass core device running locally.
Use this approach to build and test the required telemetry ingestion functionality quickly, with the added advantage of automation and containerization to reduce overall prototyping effort.
All of the patterns and solutions in this post are available to use in your own AWS account using the following overview.
Prerequisites
- Access to an AWS account.
- A Docker runtime installed locally or AWS Cloud9 cloud-based integrated development environment.
- Access to the AWS IoT Greengrass accelerators GitHub repository.
Solution walkthrough
The patterns described above are available through the AWS IoT Greengrass accelerators GitHub repository. To explore these and other available patterns, clone this repository to your development machine. Once cloned, you can follow the provided instructions to set up an AWS IoT Greengrass Core device in your environment and explore the described scenarios.
Example | Description |
---|---|
Base Implementation | A base pattern for IoT Greengrass Core device provisioning. |
Operating System Command Component | An extension of the base pattern, showcasing an example implementation of device command and control functionality. |
AWS IoT SiteWise Deployment | An extension of the base pattern, showcasing industrial telemetry ingestion through OPC-UA using AWS IoT SiteWise. |
Follow the deployment instructions provided alongside each example to get up and running quickly. You can customize these examples and adapt them to different use cases. You can also create new AWS CDK stacks using existing patterns as a foundation to create and test custom components for your own use cases. All examples can be deployed to AWS Cloud9 for rapid experimentation without the need to install or deploy any artifacts locally.
Cleanup
Clean up the resources from this post so that you don’t incur additional charges.
To delete the created CloudFormation stacks:
- Open the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation/.
- Choose the stack that you want to delete to see its details.
- Choose Delete and confirm deletion for each stack created by running the examples starting with the most recent stack. Wait for the stacks to be deleted sequentially.
Conclusion
This post illustrated how the AWS CDK, AWS IoT Greengrass, and Docker can be combined to enable rapid IoT solution prototyping on AWS. Using declarative infrastructure as code and containerization and automation, you can adopt a pattern-based prototyping approach to rapidly build common IoT solution scenarios. Spending less time on building core functionality allows you to focus on enabling differentiation and innovative capabilities for your IoT solution. This also reduces the overall time to market.
For more information, see the AWS Cloud Development Kit (AWS CDK), AWS IoT Greengrass, and AWS IoT Greengrass accelerators to help you create other prototyping patterns.