def DeleteIoTThing()

in utils/delete_iot_thing_ci.py [0:0]


def DeleteIoTThing(parsed_commands):
    try:
        iot_client = boto3.client('iot', region_name=parsed_commands.region)
    except Exception:
        print("Error - could not make Boto3 client. Credentials likely could not be sourced")
        return -1

    thing_principals = None
    try:
        thing_principals = iot_client.list_thing_principals(thingName=parsed_commands.thing_name)
    except Exception:
        print ("Could not get thing principals!")
        return -1

    try:
        if (thing_principals != None):
            if (thing_principals["principals"] != None):
                if (len(thing_principals["principals"]) > 0 and parsed_commands.delete_certificate == "true"):
                    for principal in thing_principals["principals"]:
                        certificate_id = principal.split("/")[1]
                        iot_client.detach_thing_principal(thingName=parsed_commands.thing_name, principal=principal)
                        iot_client.update_certificate(certificateId=certificate_id, newStatus ='INACTIVE')
                        iot_client.delete_certificate(certificateId=certificate_id, forceDelete=True)
    except Exception as exception:
        print (exception)
        print ("Could not delete certificate!")
        return -1

    try:
        iot_client.delete_thing(thingName=parsed_commands.thing_name)
    except Exception as exception:
        print (exception)
        print ("Could not delete IoT thing!")
        return -1

    print ("IoT thing deleted successfully")
    return 0