importboto3importjson# A session manages state about a particular configuration.# I recommend you specify profile and region - that is a good development practice.session=boto3.Session(profile_name='train',region_name='eu-west-1')# Obtain the IoT Client.iot_c=session.client('iot')
Create Thing Type
Let’s try to create a Thing TypeConnectedBulbs with the following attributes:
InvalidRequestException: An error occurred (InvalidRequestException) when calling the CreateThingType operation: Only three searchable attributes are allowed for a thing type.
Only three searchable attributes are allowed to be defined during Thing Type creation.
This Thing has an assigned Type, so it can have up to 50 attributes (Things without a Type can have maximum 3 attributes).
💡Note: during Thingcreation you can define maximum 3 attributes (even for Things with a Thing Type)! If you want to add additional attributes you need to invoke update_thing function:
1
2
3
4
5
6
7
8
9
10
iot_c.update_thing(thingName="Bulb001",attributePayload={'attributes':{'color':'white','power':'20W'},'merge':True# Specifies whether the list of attributes provided in the AttributePayload is merged with the attributes stored in the registry, instead of overwriting them.})
Searchable attributes can be used to filter lists of things without using fleet indexing. Non-searchable attributes can be used to find things, but only when fleet indexingis turned on.
I will cover the Fleet indexing service next time, now let’s focus on Thing Type and Thing Attributes.
This functionality enables the execution of jobs across all devices (represented by IoT Things) of a specific type. I will cover IoT Jobs and fleet management in the future.
Let’s try to find a specificIoT Thing: for example with production_date = '2018.03'.
{...'things':[{'thingName':'Bulb003',// this is the Thing we were looking for
'thingTypeName':'ConnectedBulbs','thingArn':'arn:aws:iot:eu-west-1:693854281758:thing/Bulb003','attributes':{'manufacturer':'GreatCorp','production_date':'2018.03','serial_number':'3.2.3.4.5'},'version':1}]}
Now let’s try to find a Thing using non-searchable attribute (for instance power):
InvalidRequestException: An error occurred (InvalidRequestException) when calling the DeleteThingType operation:
Cannot delete thing type : ConnectedBulbs. Please wait for 5 minutes after deprecation and then retry
InvalidRequestException: An error occurred (InvalidRequestException) when calling the DeleteThingType operation:
Can not delete thing type ConnectedBulbs with things associated with it
💡Note: You can delete a Thing Type, but only if it was deprecated over 5 minutes and not used by any IoT Thing.
AWS IoT Thing Type helps to organize and categorize similar IoT Things (for instance bulbs); it enables efficient management of a fleet of devices in a huge scale, production deployments.
IoT Thing with a specified Type can have up to 50 attributes (3 searchable and 47 non-searchable).