I want to integrate an Amazon API Gateway endpoint with AWS Lambda, but I'm experiencing issues.
Short description
The following reasons can cause issues for your API Gateway endpoint that integrates with Lambda:
- API Gateway doesn't have Lambda function permissions.
- Throttling occurs.
- The HTTP status code mapping is incorrect or missing.
- Lambda service exceptions aren't managed.
Resolution
Note: The following resolution uses REST API Gateway to troubleshoot.
Before you begin, turn on Amazon CloudWatch Logs to troubleshoot API Gateway errors. For Log level, choose INFO to generate execution logs for all requests.
API Gateway doesn't have Lambda function permissions
The Invalid permissions on Lambda function error occurs when API Gateway doesn't have permissions to invoke the Lambda function. To resolve this issue, see How do I resolve "Invalid permissions on Lambda function" errors from API Gateway REST APIs?
Note: If you use another service to deploy your API Gateway resources, such as AWS CloudFormation, then grant permissions to the AWS::Lambda::Permission resource.
Throttling occurs
If the backend service is throttled because of a high number of requests, then the API Gateway API might return an Internal server error. Activate an exponential backoff and retry mechanism, and then try the request again. If the issue persists, then check your API Gateway quota. If you exceed the service quota, then request a quota increase.
You might also receive Rate exceeded and 429 TooManyRequestsException errors because of Lambda function throttling issues. For more information, see How do I troubleshoot Lambda function throttling with "Rate exceeded" and 429 "TooManyRequestsException" errors?
Request a quota increase for the concurrency of the Lambda function so that the function doesn't throttle.
The status code mapping is incorrect or missing
When the HTTP status code mapping is incorrect or missing, you can receive a 500 error message similar to the following one:
"Execution failed due to configuration error: Output mapping refers to an invalid method response: 2xx/4xx/5xx".
To resolve this error, configure the API operation's integration request and response to return the correct status code.
Lambda service exceptions aren't managed
If you don't manage Lambda service exceptions, such as a Lambda function timeout, then you receive a Lambda.Unknown error. To prevent a Lambda function timeout, make your Lambda function code idempotent.
For more information, see Error handling patterns in Amazon API Gateway and AWS Lambda.
Related information
How do I troubleshoot 5xx errors for API Gateway REST API?