Files
FreeRTOS/tools/aws_config_quick_start/thing.py
Cobus van Eeden dc491debe7 LTS-development-snapshot-202002.00
LTS development changes have Source, Demo, and dependencies added for FreeRTOS-IoT-Libraries. These libraries are using FreeRTOS kernel, FreeRTOS-Plus-TCP, and FreeRTOS-Plus-Trace of V10.3.0 tag. FreeRTOS_Plus_TCP and FreeRTOS_Plus_Trace are as used as is, but a few changes are made to FreeRTOS as listed below.

    Removed FreeRTOS/Demo.
    Updated FreeRTOS/readme.txt to remove mentions about the demos.
    Removed FreeRTOS/links_to_doc_pages_for_the_demo_projects.url file as there are no demos present.
2020-02-18 17:35:31 -08:00

45 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env python
import boto3
import json
class Thing():
def __init__(self, name):
self.client = boto3.client('iot')
self.name = name
self.arn = ''
def create(self):
assert not self.exists(), "Thing already exists"
result = self.client.create_thing(thingName=self.name)
self.arn = result['thingArn']
def delete(self):
assert self.exists(), "Thing does not exist"
principals = self.list_principals()
for principal in principals:
self.detach_principal(principal)
self.client.delete_thing(thingName=self.name)
def exists(self):
list_of_things = self.client.list_things()['things']
for thing in list_of_things:
if thing['thingName'] == self.name:
return True
return False
def attach_principal(self, arn):
assert self.exists(), "Thing does not exist"
self.client.attach_thing_principal(thingName=self.name, principal=arn)
def detach_principal(self, arn):
assert self.exists(), "Thing does not exist"
self.client.detach_thing_principal(thingName=self.name, principal=arn)
def list_principals(self):
assert self.exists(), "Thing does not exist"
principals = self.client.list_thing_principals(thingName=self.name)
principals = principals['principals']
return principals