Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why i am getting this {"message": "Internal server error" } from Postman

I am new to AWS, I am getting {"message": "Internal server error"} while running the Lambda function with API Gateway in Postman.

I have checked the CloudWatchLogs, there is no error showing in the logs. But Postman returning {"message": "Internal server error"} this error.

like image 480
Deepak Sriram Avatar asked Jan 01 '23 11:01

Deepak Sriram


2 Answers

It happens when you don't return the correct API Gateway format.

Try to return this in your Lambda:

def lambda_handler(event, context):
    return {
        "statusCode": 200,
        "body": "{'Test': 'Test'}",
        "headers": {
            'Content-Type': 'text/html',
        }
    }
like image 94
bcosta12 Avatar answered Jan 04 '23 17:01

bcosta12


According to the log message you provide, it looks like the log from your Lambda function. I recommend you to enable logging feature on API Gateway side or you can use the test invoke feature on API Gateway console. They both are able to help you to debug your API.

Here is the common issues which might be able to help you diagnose the issue. 1. It doesn't have a right permission to allow API Gateway invoke your Lambda function. 2. It is set as AWS Service Proxy to your Lambda function, the response from your Lambda function doesn't return the response in the proper format.

Ref: https://forums.aws.amazon.com/thread.jspa?messageID=916452

like image 42
Hassan Murtaza Avatar answered Jan 04 '23 16:01

Hassan Murtaza