in functions/source/CfnCrossRegion/lambda_function.py [0:0]
def send(event, context, response_status, response_data, physical_resource_id, logger, reason=None):
response_url = event['ResponseURL']
logger.debug("CFN response URL: " + response_url)
response_body = dict()
response_body['Status'] = response_status
msg = 'See details in CloudWatch Log Stream: ' + context.log_stream_name
if not reason:
response_body['Reason'] = msg
else:
response_body['Reason'] = str(reason)[0:255] + '... ' + msg
if physical_resource_id:
response_body['PhysicalResourceId'] = physical_resource_id
elif 'PhysicalResourceId' in event:
response_body['PhysicalResourceId'] = event['PhysicalResourceId']
else:
response_body['PhysicalResourceId'] = context.log_stream_name
response_body['StackId'] = event['StackId']
response_body['RequestId'] = event['RequestId']
response_body['LogicalResourceId'] = event['LogicalResourceId']
if response_data and response_data != {} and response_data != [] and isinstance(response_data, dict):
response_body['Data'] = response_data
json_response_body = json.dumps(response_body)
logger.debug("Response body:\n" + json_response_body)
headers = {
'content-type': '',
'content-length': str(len(json_response_body))
}
try:
response = requests.put(response_url,
data=json_response_body,
headers=headers)
logger.info("CloudFormation returned status code: " + response.reason)
except Exception as e:
logger.error("send(..) failed executing requests.put(..): " + str(e))
raise