4
votes

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?

2
Debugging a live Lambda is practically infeasible. Do you see any logs in CloudWatch? Even if your handler fails on the first line, you should see some output there denoting the start time.Peter Wagener
Can you post the full output text of the test invoke output? (redact any sensitive data as necessary)Lorenzo de Lara

2 Answers

1
votes

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.

0
votes

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>