in gg_group_setup/cmd.py [0:0]
def _delete_thing(cert_arn, cert_id, thing_name, region, policy_name,
profile_name):
iot_client = _get_iot_session(region=region, profile_name=profile_name)
try:
# update certificate to an INACTIVE status.
logging.info('[_delete_thing] deactivating cert:{0}'.format(
cert_id))
iot_client.update_certificate(
certificateId=cert_id, newStatus='INACTIVE'
)
# Next, detach the Thing principal/certificate from the Thing.
logging.info('[_delete_thing] detach cert')
iot_client.detach_thing_principal(
thingName=thing_name, principal=cert_arn
)
logging.info('[_delete_thing] detach principal policy:{0}'.format(
policy_name)
)
iot_client.detach_principal_policy(
policyName=policy_name, principal=cert_arn
)
# finally delete the Certificate
iot_client.delete_certificate(certificateId=cert_id)
except ClientError as ce:
logging.error(ce)
# delete the Thing
logging.info('Deleting thing_name:{0}'.format(thing_name))
try:
thing = iot_client.describe_thing(thingName=thing_name)
iot_client.delete_thing(
thingName=thing_name, expectedVersion=thing['version']
)
except ClientError as ce:
logging.error(ce)