in lambda-bulk-importer/main.py [0:0]
def process_certificate(payload):
client = boto3.client('iot')
certificateText = base64.b64decode(eval(payload))
# See if the certificate has already been registered. If so, bail.
certificateObj = x509.load_pem_x509_certificate(data=certificateText,
backend=default_backend())
fingerprint = binascii.hexlify(certificateObj.fingerprint(hashes.SHA256())).decode('UTF-8')
print("Fingerprint: " + fingerprint)
if (get_certificate(fingerprint)):
try:
response = iot_client.describe_certificate(certificateId=fingerprint)
print("Certificate already found. Returning certificateId in case this is recovering from a broken load")
return response["certificateDescription"].get("certificateId")
except:
print("Certificate [" + fingerprint + "] not found in IoT Core. Importing.")
try:
response = iot_client.register_certificate_without_ca(certificatePem=certificateText.decode('ascii'),
status='ACTIVE')
return response.get("certificateId")
except botocore.exceptions.ClientError as e:
if error.response['Error']['Code'] == 'ThrottlingException':
print("ERROR: ThrottlingException. Requeue for processing.")
requeue()
if error.response['Error']['Code'] == 'UnauthorizedException':
print("ERROR: There is a deployment problem with the attached Role. Unable to reach IoT Core object.")
return None
except BaseException as e:
print("exception occurred: {}".format(e))
return None