in functions/source/CfnCrossRegion/lambda_function.py [0:0]
def cfn_handler(event, context, create_func, update_func, delete_func, logger, init_failed):
print("**3**")
logger.info("Lambda RequestId: %s CloudFormation RequestId: %s" %
(context.aws_request_id, event['RequestId']))
# Define an object to place any response information you would like to send
# back to CloudFormation (these keys can then be used by Fn::GetAttr)
response_data = {}
print("**4**")
# Define a physicalId for the resource, if the event is an update and the
# returned phyiscalid changes, cloudformation will then issue a delete
# against the old id
physical_resource_id = None
print("**4**")
logger.debug("EVENT: " + json.dumps(event))
print("**5**")
# handle init failures
if init_failed:
print("**6**")
send(event, context, "FAILED", response_data, physical_resource_id, init_failed, logger)
raise init_failed
# Setup timer to catch timeouts
t = threading.Timer((context.get_remaining_time_in_millis()/1000.00)-0.5,
timeout, args=[event, context, logger])
t.start()
try:
# Execute custom resource handlers
print("**7**")
logger.info("Received a %s Request" % event['RequestType'])
print("Received a %s Request" % event['RequestType'])
if 'Poll' in event.keys():
physical_resource_id, response_data = poll(event, context)
elif event['RequestType'] == 'Create':
physical_resource_id, response_data = create_func(event, context)
elif event['RequestType'] == 'Update':
physical_resource_id, response_data = update_func(event, context)
elif event['RequestType'] == 'Delete':
physical_resource_id, response_data = delete_func(event, context)
if "Complete" in response_data.keys():
# Removing lambda schedule for poll
if 'Poll' in event.keys():
remove_poll(event, context)
logger.info("Completed successfully, sending response to cfn")
send(event, context, "SUCCESS", cleanup_response(response_data), physical_resource_id, logger=logger)
else:
logger.info("Stack operation still in progress, not sending any response to cfn")
# Catch any exceptions, log the stacktrace, send a failure back to
# CloudFormation and then raise an exception
except Exception as e:
reason = str(e)
logger.error(e, exc_info=True)
try:
remove_poll(event, context)
except Exception as e2:
logger.error("Failed to remove polling event")
logger.error(e2, exc_info=True)
send(event, context, "FAILED", cleanup_response(response_data), physical_resource_id, reason=reason, logger=logger)
finally:
t.cancel()