def send()

in Lambda/BackupOrgPolicyManager/src/BackupOrgPolicyManager.py [0:0]


def send(event, context, response_status, response_data, physical_resource_id,
         no_echo=False):  # pylint: disable = R0913
    """
    Helper function for sending updates on the custom resource to CloudFormation during a
    'Create', 'Update', or 'Delete' event.
    """

    http = urllib3.PoolManager()
    response_url = event['ResponseURL']

    json_response_body = json.dumps({
        'Status': response_status,
        'Reason': response_data['Message'] + f', See the details in CloudWatch Log Stream: {context.log_stream_name}',
        'PhysicalResourceId': physical_resource_id,
        'StackId': event['StackId'],
        'RequestId': event['RequestId'],
        'LogicalResourceId': event['LogicalResourceId'],
        'NoEcho': no_echo,
        'Data': response_data
    }).encode('utf-8')

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

    try:
        http.request('PUT', response_url,
                     body=json_response_body, headers=headers)
    except Exception as e:  # pylint: disable = W0703
        logger.error(e)