pythonamazon-web-servicesapiaws-lambda

Return the expected status code in Postman


I am using Lambda function to return custom responses for my api endpoint.

i am returning the responses like this -

response404 = {
        "statusCode": 404,
        "body": json.dumps({"message": "Not Found"})
        }
        
        if httpStatusCode == "200":
            return output_response
        else:
            return response404

It's returning the response but not setting the status code in Postman.

404

What do i need to do to set the status to 404 in postman as well.


Solution

  • This can be done by setting up a Lambda Proxy Integration.

    enter image description here

    The response of the lambda function needs to be in this format ->

    response = {
            "statusCode": 404,
            "headers": {
                "Content-Type" : "application/json"
            },
            "body": json.dumps(error_handler)
        }
    
    return response