Question

Difficulty: EasyTroubleshooting API Gateway Errors and CORS

A client receives a 500 Internal Server Error when attempting to call an Amazon API Gateway resource secured by a custom Lambda Authorizer. The Lambda Authorizer execution completes successfully with no errors in its Amazon CloudWatch logs. Which of the following is the most likely cause of this behavior?

  1. The custom Lambda Authorizer returned a response JSON payload that does not conform to the expected format containing principalId and policyDocument.Answer
  2. B
    The CORS configuration on the API Gateway resource is missing the Access-Control-Allow-Origin header.
  3. C
    The client application sent an authorization token that is invalid or has expired.
  4. D
    The backend integration Lambda function is returning a plain text string instead of a structured JSON response.

Answer

The custom Lambda Authorizer returned a response JSON payload that does not conform to the expected format containing principalId and policyDocument.
The correct response points out that a malformed JSON payload returned by the custom Lambda Authorizer (such as omitting principalId or policyDocument) causes API Gateway to fail validation, leading to a 500 Internal Server Error even if the Lambda code itself runs successfully without throwing errors.

Step-by-Step Solution

1
Analyze the HTTP status code and logs.
The client receives a 500 Internal Server Error, but the Lambda Authorizer execution completes successfully with no runtime errors in CloudWatch.
This indicates that the authorizer function executed successfully without throwing an exception, but API Gateway failed to process the output returned by the function.
2
Verify the required output format for Lambda Authorizers.
Lambda Authorizers must return a structured JSON response containing the principalId, policyDocument (with Statement, Action, Effect, Resource), and optionally context.
API Gateway requires this specific structure to validate permissions. If any of these fields are missing or incorrectly formatted, API Gateway cannot evaluate the policy and defaults to a 500 Internal Server Error.

Key Concept

API Gateway Lambda Authorizer response validation
Rate this question