(AWS Lambda) "errorMessage": "Unable to marshal response: Object of type HTTPResponse is not JSON serializable"

Viewed 4174

So I have been testing my server API via POSTMAN and the result looks like this: enter image description here

My goal with the AWS Lambda is to show (in the log) whatever the json response you get from this API. My code in the lambda looks like this:

import json
import urllib3


def lambda_handler(event, context):
    http = urllib3.PoolManager()

    response = http.request('GET',
                        "http://106.10.54.227:9062/api/v1/weather-api",
                        retries = False)
    
    return response

However when I test this lambda function, I get this error:

Response:
{
  "errorMessage": "Unable to marshal response: Object of type HTTPResponse is not JSON serializable",
  "errorType": "Runtime.MarshalError"
}

What I do not understand is the fact that the response from the API is the JSON itself so I don't know why it complains it is not serializable.

Is there any way to fix this issue? Thanks a lot!

0 Answers
Related