简体   繁体   中英

AWS Lambda Integration Response in API Gateway - {“message”: “Internal server error”}

i hope this isn't a duplicate. I searched through other entries and none seemed to address the problem i'm seeing.

We have an AWS Lambda function written in Python 3.6. The Lambda function is executed through API Gateway using the Lambda proxy integration. The function is initiated without problem and the processing executes without a problem. However, no matter what we seem to do in trying to send a response, the client receives "{"message": "Internal server error"}" I don't know that it's important, but the client for our test is Postman.

We've stripped out all of our business logic and isolated the code that does the return and we still get have the same problem.

the code is:

    import json
    def lambdaTest(event, context)
        response = {}
        dummybody = {'body':'something'}
        response['statusCode'] = 200
        response['body'] = dummybody
        response["headers"] = {"Content-Type": "application/json"},
        return json.dumps(response)

i'm sure I'm doing something wrong that's simple as I don't seem many posts about this problem. I would very much appreciate any help. Thanks.

Folks, I figured it out... one silly problem and one thing I didn't realize about the format of the response. The silly problem was that I turned the header element into an array because I had a trailing comma (I looked at the 100 times and didn't see it). But even when I commented out setting up the header, it still had the same problem. The aspect of the response that i didn't realize is that the body is expected to be a string. So, I had to encapsulate the JSON document I wanted to return in a string. That fixed the problem.

i hope this can help someone else

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM