in assets/lambdas/lambdas.py [0:0]
def send_cfnresponse(event, context, response_status, data: dict):
response_url = event['ResponseURL']
print('CFN response url: {}'.format(response_url))
response_body = {}
response_body['Status'] = response_status
response_body['Reason'] = 'See the details in CloudWatch Log Stream: ' + context.log_stream_name
response_body['PhysicalResourceId'] = context.log_stream_name
response_body['StackId'] = event['StackId']
response_body['RequestId'] = event['RequestId']
response_body['LogicalResourceId'] = event['LogicalResourceId']
response_body['Data'] = data
json_response = json.dumps(response_body)
print("Response body:\n" + json_response)
headers = {
'content-type': '',
'content-length': str(len(json_response))
}
try:
response = requests.put(response_url, data=json_response, headers=headers)
print("Status code: " + response.reason)
except Exception as e:
print("send(..) failed executing requests.put(..): " + str(e))