Search code examples
amazon-kinesis-firehose

Kinesis Firehose HTTP_Endpoint destination Response format


What is the right format of the Response for Kinesis Firehose with http_endpoint as destination. Have already gone through the aws link: https://docs.aws.amazon.com/firehose/latest/dev/httpdeliveryrequestresponse.html#responseformat

I have used the below lambda code in python(integrated in api) as well as with many other options, but keep getting the below error message. The test is performed using the "Test with Demo Data" option

sample code:

def lambda_handler(event, context):
    data ={}
    headersD = {}
    
    headersD['content-length'] = 0
    headersD['content-type'] = 'application/json'
    data['requestId'] = 'ed4acda5-034f-9f42-bba1-f29aea6d7d8f'
    data['timestamp'] = '1578090903599'
    bodyDetail= {}
    data['body'] = ''
    data['headers'] =headersD
    data['statusCode']=200
    resp = json.dumps(data)
    return resp

error response as seen in the logs:

The response received from the endpoint is invalid. See Troubleshooting HTTP Endpoints in the Firehose documentation for more information. Reason:. Response for request 'request-Id' is not recognized as valid JSON or has unexpected fields. Raw response received: 200 "HttpEndpoint.InvalidResponseFromDestination"


Solution

  • Here is the sample output that worked(in python):

        
    responseBody = {
        "requestId": "requestId",
        "timestamp": 123456
    }
    resp = {
    "headers": {"Content-Type": "application/json", "Content-Length": 100},
    "body": json.dumps(responseBody),
    "statusCode": 200
    }
    
    return resp