#!/usr/bin/python # -*- coding: utf-8 -*- ############################################################################## # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # # # # Licensed under the Apache License Version 2.0 (the "License"). # # You may not use this file except in compliance with the License. # # A copy of the License is located at # # # # http://www.apache.org/licenses/ # # # # or in the "license" file accompanying this file. This file is distributed # # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, # # express or implied. See the License for the specific language governing # # permissions and limitations under the License. # ############################################################################## import requests import json def send(event, context, response_status, response_data, physical_resource_id=None, no_echo=False): response_url = event['ResponseURL'] response_body = {} response_body['Status'] = response_status response_body['Reason'] = 'See the details in CloudWatch Log Stream: ' + context.log_stream_name 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['NoEcho'] = no_echo response_body['Data'] = response_data json_response_body = json.dumps(response_body) headers = { 'content-type': '', 'content-length': str(len(json_response_body)) } try: response = requests.put(response_url, timeout=20, data=json_response_body, headers=headers) print("Status code: " + response.reason) except Exception as e: print("send(..) failed executing requests.put(..): " + str(e))