
In this exercise, you are going to use the thing groups functionality in the IoT Registry to manage several things at once. You can use this functionality to categorize things into groups, create a hierarchy of groups, and attach a policy to a group to change permissions and behavior of its things all at once.
You will walk through a solution which has the following tasks:
You should only use the architecture and sample code displayed below as a guideline.
Your smart air conditioners are getting online all over the world as you could see in the last section. To improve the way you manage things at scale, you will organize them in a layered hierarchical structure. The Location group should be at the root level.
The diagram below shows the hierarchical organization after creating all the groups in this exercise.

For the following tasks, you will use both the AWS Console and AWS CLI to execute commands and procedures. First, you will organize your things into groups.
Open the AWS IoT Console, if it is not already opened:
iot core on the Find Services
Under the IoT Home page, on the left menu:
Location as Nameroot level group as DescriptionDeviceRunningType as Attribute keyProduction as ValueLevel as Attribute keyRoot as Value

In order to speed up the other groups creation, let´s use Cloud9 and the AWS CLI commands.
You will start making children groups by creating the East-USA group. This group helps you define the first layer of specialization for your fleet and is the child of the Location group.
You will create your thing group using the create-thing-group command in the AWS CLI. The command requires parameters, similar the ones you have used in AWS console, except the group hierarchy relationship, represented by the --parent-group-name parameter.
Go back to the Cloud9 tab opened previously:
# Create a Thing Group
aws iot create-thing-group \
--thing-group-name East-USA \
--parent-group-name Location \
--thing-group-properties 'thingGroupDescription=child level group,attributePayload={attributes={DeviceRunningType=Production,Level=us-east},merge=true}'
Next, create two child groups: East-USA group, NYC and Miami respectively. Concatenate the two commands together to improve speed:# Create a Thing Groups
aws iot create-thing-group \
--thing-group-name NYC \
--parent-group-name East-USA \
--thing-group-properties 'thingGroupDescription=child level group,attributePayload={attributes={DeviceRunningType=Production,MaintWindow=00-06},merge=true}' &&\
aws iot create-thing-group \
--thing-group-name Miami \
--parent-group-name East-USA \
--thing-group-properties 'thingGroupDescription=child level group,attributePayload={attributes={DeviceRunningType=Production,MaintWindow=00-06},merge=true}' \
&& echo "Command completed successfully" || echo "Error executing the command"
You have created the first branch of the organization hierarchy. Now you have to define the West-USA and South-America organizations and their respective child groups. To quickly define this configuration, run the concatenated group creation command shown below. Be aware of different attributes and child relationships with higher hierarchy levels of the organization.# Create Thing Groups
aws iot create-thing-group --thing-group-name West-USA --parent-group-name Location --thing-group-properties \
'thingGroupDescription=child level group,attributePayload={attributes={DeviceRunningType=Production,Level=us-west},merge=true}'&&\
aws iot create-thing-group --thing-group-name LasVegas --parent-group-name West-USA --thing-group-properties \
'thingGroupDescription=child level group,attributePayload={attributes={DeviceRunningType=Production,MaintWindow=00-06},merge=true}'&&\
aws iot create-thing-group --thing-group-name SanFrancisco --parent-group-name West-USA --thing-group-properties \
'thingGroupDescription=child level group,attributePayload={attributes={DeviceRunningType=Production,MaintWindow=00-06},merge=true}' &&\
aws iot create-thing-group --thing-group-name South-America --parent-group-name Location --thing-group-properties \
'thingGroupDescription=child level group,attributePayload={attributes={DeviceRunningType=Production,Level=South-America},merge=true}'&&\
aws iot create-thing-group --thing-group-name SaoPaulo --parent-group-name South-America --thing-group-properties \
'thingGroupDescription=child level group,attributePayload={attributes={DeviceRunningType=Production,MaintWindow=00-06},merge=true}'\
&& echo "Command completed successfully" || echo "Error executing the command"

Use the following steps to inspect the groups in the AWS IoT console and verify that all the commands ran successfully.
Open the AWS IoT Console, if it is not already opened:
iot core on the Find Services
Under the IoT Home page, on the left menu:



Keep in mind that everything you created so far is searchable from fleet Indexing. You are going to enable it to include the things on this organization.
Congratulations! You have added things to groups and organized your fleet into logical groups. You can now move to the next section.