in functions/source/lex_custom_lambda/lex_custom_lambda.py [0:0]
def send(event, context, response_status, response_data, physical_resource_id):
responseUrl = event['ResponseURL']
logger.debug("CF Response URL: " + responseUrl)
response_body = {}
response_body['Status'] = response_status
if response_status == FAILED:
response_body['Reason'] = response_data['Message']
else:
response_body['Reason'] = "completed"
response_body['PhysicalResourceId'] = physical_resource_id or context.log_stream_name
response_body['StackId'] = event['StackId']
response_body['RequestId'] = event['RequestId']
response_body['LogicalResourceId'] = event['LogicalResourceId']
response_body['Data'] = response_data
json_response_body = json.dumps(response_body)
logger.info("CF Response Body: %s", json.dumps(json_response_body))
headers = {
'content-type': '',
'content-length': str(len(json_response_body))
}
try:
response = requests.put(responseUrl,
data=json_response_body,
headers=headers)
logger.info("CF Status code: %s ", response.reason)
except Exception as e:
logger.error("send(..) failed executing requests.put(..): %s", str(e))