in lambda-issuer-acmpca/main.py [0:0]
def deploy_thing( device_id, certificate_arn ):
iot = boto3.client('iot')
# Identify if an existing Thing exists with the device ID. If yes, then use
# that Thing for certificate attachment. Otherwise, create a new Thing.
thing_name = None
try:
iot.describe_thing( thingName = device_id )
thing_name = device_id
except:
print( "Thing [{}] does not exist. Will create.".format( device_id ) )
if ( thing_name == None ):
try:
iot.create_thing( thingName = device_id )
thing_name = device_id
except:
print( "Thing [{}] does not exist and failed to create.".format( device_id ) )
return False
# Attach the Thing to the Certificate.
try:
iot.attach_thing_principal( thingName = thing_name, principal = certificate_arn )
except:
return False
return True