Building Digital Twins with AWS IoT TwinMaker
Understanding basic concepts of TwinMaker and building basic projects with custom CloudFormation templates.
Industries are adopting digital twins to make better operational and strategic decisions. TwinMaker is a new AWS service released on the 22nd of April 2022 by AWS and is part of IoT core services. TwinMaker helps users create digital twins of the real world more easily and faster.
AWS IoT TwinMaker is generally available in regions of the US East (N. Virginia), US West (Oregon), Asia Pacific (Singapore), Asia Pacific (Sydney), Europe (Frankfurt), and Europe (Ireland), with more regions to come soon.
In this article, we’ll cover the explanation of the main components of TwinMaker. Then we’ll build a simple digital twin using a custom CloudFormation template.
Let’s do it.
Understanding the main elements of TwinMaker:
The first step is to understand what is a workspace, entity, components or data connectors, tags, resources, scenes, etc.
To understand all TwinMaker components, we can read the official documentation.
Workspace:
A workspace is a top-level container for your digital twin application. In it you create a set of entities, components, scene assets, and other resources for your twin. It also serves as a security boundary to manage access to the digital twin application and its resources. Each workspace is linked to the Amazon S3 bucket; workspace data is stored in it. You use IAM roles to restrict access to your workspace.
Entity:
Entities are digital representations of the elements in a digital twin that capture the capabilities of that element. This element can be a piece of physical equipment, a concept, or a process. Entities have components associated with them, which provide data and context. The default view of the entity and component system is hierarchical. With TwinMaker, you can organize entities into custom hierarchies for more efficient management.
Components (Data connectors):
Components provide context and data for the entities in the scene. You use them to save static or dynamic data using custom component connectors. We can connect TwinMaker entities with time series data sources using AWS Lambda or other services.
Tags:
A tag is a type of node representing data from a component (through an entity). A tag can be associated with only one component. A tag is an annotation added to a specific coordinate of a scene. The tag connects this scene to the knowledge graph using an entity property. You can use a tag to configure the behavior or visual appearance of an item in the scene, such as an alarm.
Resources:
Resources are images and three-dimensional models used to create a scene. A resource can represent a single piece of equipment or a complete site.
Scenes:
The most important component provides a visual context for the data connected to the service. The scenes can be created with a single 3D model in glTF
or glb
format, or a combination of many models. Additionally, the scenes contain tags to identify specific areas or points of interest. The scenes can be organized inside workspaces, where multiple scenes can be grouped.
If we are keen to learn more about the TwinMaker service's components, we can find all the information related to it in the following link.
Building TwinMaker project
Now let’s get to work; the idea is to learn how to implement a basic digital twin using TwinMaker. We’ll use the CloudFormation template to deploy all necessary resources inside the AWS cloud; it’s the access to the code allocated in GitHub.
Remember to review the service's quotas and limitations to understand what TwinMaker allows for our solution.
Architecture diagram
In the first step, we’ll understand the diagram of the AWS infrastructure to achieve the goals of this post. Our AWS services do not depend on the previous networking configured.
In the diagram above, we can see so many AWS services. Don’t worry about them; we’ll create them using a custom CloudFormation template. I’m going to explain the main of each one of these components to understand in a better way our solution:
- CloudWatch (Event Bridge Rule): In this case, we are using it to create a scheduled task to execute the lambda function every 10 minutes.
- Seeder-lambda: Lambda function executed every 10 minutes by the rule configured in CloudWatch. The goal of this is to simulate the time series data and save it in Time Stream Db. As we haven’t real measures of actual sensors, we need to simulate this information.
- Time Stream DB: Database to save time series data. In our case, we will save 2-time series values related to pressure and temperature. In a real scenario, you can save all the time series data from all the sensors available in the factory or entity you want to digitalize.
- Timestream-connector-lambda: Lambda function is the data source connector with TwinMaker. The components make a request to the lambda connector, the lambda builds a query to the database, and finally transforms the response and return it to TwinMaker. We’ll use one custom connector, but we can use many connectors as data sources in a real solution.
- TwinMaker assets bucket: S3 bucket where TwinMaker saves all resources. Its bucket is necessary and required to create a workspace in TwinMaker.
- AWS Grafana: Grafana application is administered by AWS. We’ll use it for the visualization layer to show the scenes and the time series data.
- TwinMaker Workspace: This is where you can set up and preview elements such as components, entities, resources, and scenes. Using AWS TwinMaker as a digital twin solution, you can view and configure these elements in one place.
Setting up the AWS components using a custom CloudFormation template
Now we’ll deploy all AWS components in our testing account. To achieve this, we’ll use a CloudFormation template. Download the following repository code on your local machine, and you must install the AWS CLI or SAM CLI.
In my case, I’m using SAM CLI to deploy the stacks of CloudFormation if you are keen to know more about SAM, please review the following link.
I worked a lot to make the deployment of the AWS resources easy using the following CloudFormation template.
To deploy all AWS resources, we need to stay in the root folder of the repository code share before, and we’ll execute the following command:
In the case that we don’t have SAM installed, we’ll try using the following AWS CLI command:
Remember, when we end testing the solution, delete all AWS resources to prevent the expended billing.
If all is right, all AWS resources presented in the diagram were deployed in our account.
Explore TwinMaker Workspace
When we access the TwinMaker Workspace in the console, we can view all items related to TwinMaker. It is important to note that the IAM Role associated with the service is crucial to understand the necessary permissions for communication with the services that TwinMaker interacts with. To view specific permissions of this role, you can check the IAM module and search for the role or look in the CloudFormation template.
Understanding the Entities
In this particular case, we have two entities, how an entity is a digital representation of a component in real life, the first entity is an OFFICE entity, and it has associated one component called TemperatureComponent with this component, TwinMaker will consult the time series values using a custom connector; the other entity is a WATER TANK this entity is a representation of a tank of water and the component associated is the PressureTankComponent that is related with the measure time series value of pressure.
Create a scene in AWS TwinMaker by the console
To create a digital representation of an office with a water tank, we will use a 3D model and add tags for the temperature of the office and the pressure of the tank. We will use TwinMaker’s scene builder tools to add the tags, configure rules for the behavior of the tags, and add extra cameras for navigation. The process will be demonstrated with screenshots.
Create scene
To create a new scene using TwinMaker, select the Scenes option on the left side, then select the Create scene option. A modal will appear, where you need to enter a Scene ID and an optional description and then click on the Create button to create the scene.
Add 3D model into Scene
To add a 3D model in the TwinMaker editor, select the plus icon and click on the Add 3D model button. A modal will appear where you can select the resource. If you don’t have any resources uploaded, you can use the provided 3D model. Only certain file types are supported, such as BIN, GLB, glTF, PNG, PDF, JPG, JPEG, and MP4.
Next, the 3D model will be uploaded in the scene; if the model has not any color, please change the setting Environment Preset:
Add new cameras to the scene
TwinMaker allows you to add many cameras to the scene, which enhances the user’s interaction with the scene. To add a new camera, select the plus icon and choose the Add camera from the current view option.
Add tags and associate them with entities
To track the office's temperature and the tank's pressure, we need to create two tags in TwinMaker. To create a tag, select the plus icon and the Add tag option. Once created, the tag can be moved around the scene, and its properties, such as name, rules, and association with the entity, component, and property, can be configured on the right side.
Create custom rules
TwinMaker is a tool that allows users to create rules, which are sets of conditions that determine the behavior of tags. For example, a rule can be set to display an error icon on a tag if the pressure exceeds a certain threshold. These rules can then be applied to specific tags by selecting the tag and selecting the corresponding rule in the “Rule ID” section.
To configure a rule in TwinMaker, navigate to the “Rules” tab, enter the ID of the rule (e.g., “OfficeTemperatureRule”), and add a new condition or statement. An example of a rule would be setting an error icon to appear when the temperature in the office exceeds a certain threshold.
Configure Grafana dashboard
Once the scene is configured in TwinMaker, the next step is to set up a Grafana dashboard to view the 3D visualization and display time series values for temperature and pressure measures. This can be done by following the necessary steps.
Add SSO user to Grafana
To add a user or group to the Amazon Grafana service on the AWS console, search for “Amazon Grafana” in the search bar and navigate to the service. Select “Assign New User or Group” and choose the user or group you want to add. Ensure that admin permissions are granted to this user. Once the user is added, they can access the Grafana application in the SSO portal.
Add a Data source (TwinMaker) in Grafana
When using Amazon Grafana management in AWS, the TwinMaker plugin is not required, as all official AWS plugins for Grafana are pre-installed. To set up the data source, go to the left-side menu and select the configuration button. Then, select “Data Sources” and add a new data source. Search for the TwinMaker data source and select “Configure”. In the configuration section, input the Assume Role ARN in the appropriate field.
Select the region where TwinMaker is deployed and select the workspace. Finally, save and test; if all is good, you can see a message of successful configuration.
Configure the panels
The goal is to create a dashboard with three panels. One for 3D visualization, one for office temperature time series data, and one for water tank pressure time series values. To create a dashboard, select the plus icon on the left side and select the “Dashboard” option. Then, select “Add new panel” and configure the panels for time series values and 3D visualization using the provided image as a guide.
Now, if all panels are configured succeed, you can see a similar dashboard.
Conclusion
It was a basic introduction to creating a basic digital twin using native tools in AWS. We implemented a basic digital twin with a few sensors. TwinMaker allows the capability to digitalize an entire factory. The cookie factory example it’s an exemplary implementation of the service using another’s extra AWS service. One of the essential advantages of using the TwinMaker is that you do not need to have a previous networking configuration in your account; you don’t worry about the scalability of the service. It’s the responsibility of AWS.
Thanks for reading, and I hope it has been to your liking.