def send_response(request_msg, data=None, error=None): """ Send response message to S3 url :param request: :param data: :param error: :return: """ response = ResponseMessage(request_msg) if data: response.data = data if error: response.error = error try: # PUT the response file to the S3 pre-signed URL requests.put(url=request_msg.response_url, data=response.to_json(), headers={"Content-Type": ""}, verify=True ).raise_for_status() log.debug((response.to_json())) log.info("Successfully send response %s for RequestID:%s"% (request_msg.response_url, request_msg.request_id)) except Exception, e: print("Got Error! - %s"% e.message) log.exception("Failed sending response %s for RequestID:%s"% (request_msg.response_url, request_msg.request_id)) log.exception("Error: %s"% e.message) raise AWSError("Unable to send response!")