An AWS Lambda invocation can raise errors for a variety of reasons1. A few examples are listed below. Invocation errors will make Lambda return a 400-series or 500-series HTTP status code.
For a complete list of invocation errors, please refer to the AWS documentation2.
- Larger than the Lambda limit3
- Contains a parameter with invalid type
- Trying to invoke an inexistent function
- Client doesn’t have permissions to invoke the required function
- Account services are suspended
- Reached the limit of concurrent Lambda microVMs running
AWS Lambda Function errors happen when, for example:
- Developer’s code raises an exception
- There is a syntax error in the code preventing the execution
- The execution reaches the timeout limit
AWS Lambda will automatically add the
X-Amz-Function-Error header and a JSON as the response with details about the function error. Because of that, it is a good practice to avoid the code from raising exceptions, since it will expose internal implementation details. This could potentially compromise the application security.
To avoid this issue, developers should catch all exceptions in the
function_handler, log them and return a sanitized and gentle response to the requester.
AWS provides guidance on handling function exceptions for all runtimes supported by Lambda. Below is list with reference pages for each runtime: