in lambda-issuer-iotcore/main.py [0:0]
def lambda_handler(event, context):
csr = base64.b64decode(event['headers']['device-csr'])
req = load_certificate_request( FILETYPE_PEM, csr )
device_id = req.get_subject().CN
response = provision_certificate( csr )
region = context.invoked_function_arn.split(":")[3]
account = context.invoked_function_arn.split(":")[4]
# Send the certificate to AWS IoT. We assume the issuing CA has already
# been registered.
if response is None:
return None
certificate_body = response['certificatePem']
certificate_arn = response['certificateArn']
# Create the Thing object and attach to the deployed certificate
response = deploy_thing( device_id, certificate_arn )
# The entire transaction failed, so report failure.
if ( response == False ):
return None
# Create the Policy if necessary, and attach the created Policy (or
# existing Policy) to the Thing.
deploy_policy( certificate_arn, region, account )
if ( response == False ):
return None
# Return the certificate to API Gateway.
return certificate_body