The Internet of Things on AWS – Official Blog

How to improve device discoverability by unlocking 50 AWS IoT thing type attributes

Introduction

If you are using or planning to use AWS IoT Core to manage your fleet of Internet of Things (IoT) devices and wondering how to search for and discover a particular device or a set of devices based on their identities and capabilities, then using attributes for AWS IoT thing types is one of the recommended ways to make device discovery easier.

A ‘thing’ is the logical name for entities like the IoT-enabled devices in AWS IoT Core. While provisioning a thing, you can attach searchable attributes to enable easier identification and searching within the AWS IoT registry.

Why would someone want to search things from the AWS IoT registry? To answer that question, let’s take the use case of connected lights where a Lighting-as-a-Service provider (LaaS) or their customers (through self-service portals) need to determine from their lighting installed base, how many are of a particular product-type, model-number, wattage, luminosity, color, and manufacturing batch.

AWS IoT Core restricts attaching only 3 searchable attributes to a thing, and this may not be enough if you need to discover devices based on additional attributes. In this blog post, we will show how to mitigate this challenge using a combination of AWS IoT Core thing types and AWS IoT Device Management fleet indexing.

With fleet indexing, fleet administrators can organize, investigate, and troubleshoot fleet of devices. They can query a group of devices, and aggregate statistics on device records that are based on different combinations of device attributes, including state, connectivity, and device violations. For example, you can query information, such as how many light bulbs of a certain model installed at a certain location are currently disconnected and are running the older version of firmware.

Prerequisites

This blog post requires a basic understanding of the device provisioning feature of AWS IoT Core and the fleet indexing feature of AWS IoT Device Management.

Walkthrough

Let’s now see how to add a non-searchable attribute to a thing and how to use fleet indexing for search even while using non-searchable attributes.

Let’s provision a thing ‘MyFirstThing’ and attach searchable attributes to it. As you can see in the following snapshot, you can only attach 3 searchable attributes.

Provision a thing with 3 attributes

To add more attributes to this thing, you can attach a ‘thing type’ to the thing.

‘Thing type’ allows you to store description and configuration information that is common to all things associated with the same thing type. This simplifies the management of things in the registry. For example, instead of assigning attributes to each and every light bulb individually, you can create a thing type called ‘LightBulb’ and associate attributes of a light bulb like serial number, luminosity, wattage, and more. Moreover, if you change the thing type of the existing thing to ‘LightBulb,’ it would inherit the attributes of the thing type and you could specify values for each of the attributes defined in the ‘thing type.’

Though assigning a thing type to a thing is an optional activity, its usage unlocks a new section of 47 additional ‘non-searchable thing attributes.’ With this association, you now have access to a total of 50 attributes as highlighted in the following snapshot.

Attach a thing type to a thing

For this post, we have already created a thing type ‘LightBulb’ with searchable attributes, such as manufacturer, serial number, and wattage, and assigned it to ‘MyFirstThing.’ We have also attached 3 non-searchable attributes (color, firmware type, luminosity) as you can see in the following snapshot.

View searchable and non-searchable attributes

Now, let’s try to search things using the ‘list things’ command from the AWS CLI. We can see that searching with ‘searchable’ attributes, the command returns the matching thing ‘LightBulb_1’.

aws iot list-things --attribute-name "wattage" --attribute-value '40'

{

    "things": [

        {

            "thingName": "LightBulb_1",

            "thingTypeName": "LightBulb",

            "thingArn": "arn:aws:iot:ap-south-1:************:thing/LightBulb_1",

            "attributes": {

                "Color": "White",

                "Firmware_Type_Version": "Smart_LED.1.0",

                "Luminosity": "100",

                "manufacturer": "xyz_corp",

                "serialnumber": "123",

                "wattage": "40"

            },

            "version": 5

        }

    ]

}

However, searching with ‘non-searchable’ attributes, the command returns nothing as the attributes added through thing type are classified as non-searchable.

aws iot list-things --attribute-name "Color" --attribute-value 'White'


{
    "things": []
}

This is where the AWS IoT Device Management fleet indexing feature helps, enabling you to run search queries even on ‘non-searchable’ thing attributes.

With AWS IoT Device Management fleet indexing, you can index, search, and aggregate your device data from the following sources: AWS IoT registry, AWS IoT Device Shadow, AWS IoT connectivity, and AWS IoT Device Defender violations.

While the fleet Indexing feature has the aforementioned as its primary capabilities, for this blog post we will focus only on indexing and searching based on thing type attributes.

Now, let’s enable fleet indexing (skip this step if already enabled) using AWS IoT console, but it can also be enabled from the CLI. Select Settings from the left panel and scroll down to Fleet indexing and select Manage indexing as shown following:

Fleet indexing view

On the Manage fleet indexing screen, toggle the switch to activate fleet indexing as shown following and select Update at the bottom of screen to save settings.

Activate fleet indexing

Other check boxes shown on the previous screen allow indexing and search queries based on device shadows, connectivity status, and Device Defender violations which are out of the scope of this post and hence are not selected here.

After fleet indexing is enabled, select Advanced search from the AWS IoT Manage Things console as shown in the following snapshot.

Advanced search screen

Using the search box, search for non-searchable attributes, for example, ‘color’ having value ‘white’ and you will see that the things with the matching attribute value will appear as the search result at the bottom of the screen as shown following.

View Search Results

You can also use AWS CLI to run the similar fleet index query for devices with non-searchable attribute ‘color’ having value ‘white,’ wherein thing(s) with matching attribute values are returned, as indicated following.

aws iot search-index –query-string ‘attributes.color=White’


{
    "things": [
        {
            "thingName": "LightBulb_1",
            "thingId": "******************************",
            "thingTypeName": "LightBulb",
            "attributes": {
                "Color": "White",
                "Firmware_Type_Version": "Smart_LED.1.0",
                "Luminosity": "100",
                "manufacturer": "xyz_corp",
                "serialnumber": "123",
                "wattage": "40"
            }
        }
    ]
}

However, it is also important to note that AWS IoT Device Management fleet indexing is meant for administrative purposes, allowing administrators to organize, investigate, and troubleshoot fleets of devices and should be used for such activities only.

Fleet indexing and search features are metered by the number of index updates and search queries executed. Refer to the pricing page for further details and also refer its limits and quotas here.

Conclusion

In this post, I have shown you how to enhance device discoverability using AWS IoT thing types and AWS IoT Device Management fleet indexing. Thing types enable you to attach additional attributes (non-searchable) to things, and despite these attributes being non-searchable, you can use the fleet indexing feature to search based on non-searchable attributes, enabling you to conveniently filter and find these devices out of your large fleet of IoT devices.

For more AWS IoT Core learning resources, please visit the website.

Ankush Sharma

Ankush Sharma

Ankush Sharma is a Solution Architect at AWS India Private Limited, based in Delhi, India. He is part of Enterprise Greenfield team and helps customers migrate, design and operate secure and scalable solutions on AWS using breadth and depth of AWS services to deliver expected business outcome. Ankush has over 17 years of experience in the IT industry and when not at work he enjoys spending time with his family and reading books.