in community/custom_resources/python_custom_resource_helper/crhelper.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: {}".format(response_url))
response_body = dict()
response_body['Status'] = response_status
msg = 'See CloudWatch Log Stream: {}'.format(context.log_stream_name)
if not reason:
response_body['Reason'] = msg
else:
response_body['Reason'] = str(reason)[0:255] + ' ({})'.format(msg)
response_body['PhysicalResourceId'] = physical_resource_id or 'NONE'
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{}".format(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: {}".format(response.reason))
except Exception as e:
logger.error("send(..) failed executing requests.put(..): {}".format(e))
raise