def send()

in source/lib/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: " + 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
    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']
    if response_data and response_data != {} and response_data != [] and isinstance(response_data, dict):
        response_body['Data'] = response_data

    logger.debug("<<<<<<< Response body >>>>>>>>>>")
    logger.debug(response_body)
    json_response_body = json.dumps(response_body)

    headers = {
        'content-type': '',
        'content-length': str(len(json_response_body))
    }

    try:
        if response_url == 'http://pre-signed-S3-url-for-response':
            logger.info("CloudFormation returned status code: THIS IS A TEST OUTSIDE OF CLOUDFORMATION")
        else:
            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