Kristian
Kristian

Reputation: 21830

Debugging error in AWS Lambda and API Gateway Endpoint response

I have a lambda function that is wired up to work with API Gateway. When I run it locally it works, when I simulate it with serverless offline it works.

But against the published dev endpoint, it returns an error 500 and a json object with an error message:

{
  "message": "Internal server error"
}

In the CloudWatch logs, there are no errors. In the callstack in the API gateway endpoint testing page, I see my correct response body in the Lambda portion of the process, and then when it gets to the API gateway response step, something goes wrong.

How should I debug API Gateway when there aren't any errors in logs?

Upvotes: 4

Views: 1061

Answers (2)

freezed
freezed

Reputation: 1339

To get API Gateway feeding cloudWatch :

  1. create a new role with AmazonAPIGatewayPushToCloudWatchLogs in IAM
  2. copy the role ARN arn:aws:iam::<account id>:role/<role name>
  3. paste it in field : API Gateway > Settings > CloudWatch log role ARN
  4. Go to APIs > <API name> > Stages > Settings > CloudWatch Settings and :
    • check Enable CloudWatch Logs
    • choose Log Level (INFO to see everything)
    • check Log full requests/responses data (dump the entire initial request and response into the log)
    • check Enable CloudWatch Metrics (to see Graph in CloudWatch)

Now your logs can be viewed in :

  • CloudWatch > Logs

under a name like API-Gateway-Execution-Logs_<api id>/<api stage>

Upvotes: 0

Cristian Dan
Cristian Dan

Reputation: 173

If you're writing it in node, it could be that your node version is different than 4.3.2 (the one that AWS Lambda uses) and that's why testing offline and locally works but not in the AWS Lambda.

This happened to me before, when I was using let.

You could use nvm to install node v 4.3.2 to test it locally or you could look here to see what features are you allowed to use in your code.

Upvotes: 1

Related Questions