A frontend web application hosted on `https://app.company.internal` receives a `403 Forbidden` error with the message 'User is not authorized to access this resource' when sending requests to various endpoints of a private Amazon API Gateway REST API. The API uses a custom Lambda Authorizer with caching enabled. The developer notes that the client's first API call to `GET /orders` succeeds, but a subsequent call to `POST /payments` by the same user within a five-minute window fails with the `403 Forbidden` error. The CloudWatch logs show the authorizer executes successfully only for the first request. Which of the following is the most likely cause of this error?
- AThe Lambda Authorizer is configured using Lambda Proxy Integration and failed to format its JSON response with the mandatory keys `statusCode`, `headers`, and `body`.
- BThe REST API is configured with a Cognito User Pool Authorizer, which expects a custom Lambda function to return a JWT token in the authentication response instead of an IAM policy document.
- The Lambda Authorizer generated an IAM policy document that hardcoded the specific resource ARN of the first request (`GET /orders`) instead of using wildcards, which was then cached and applied to the subsequent request.Cevap
- DThe API Gateway CORS configuration for the `POST` method lacks the `Access-Control-Allow-Origin` header, causing API Gateway to block the request and return a `403 Forbidden` error to the client.
Cevap
The Lambda Authorizer generated an IAM policy document that hardcoded the specific resource ARN of the first request instead of using wildcards, which was then cached and applied to the subsequent request.
The correct answer is that the Lambda Authorizer generated a policy document that hardcoded the specific resource ARN of the first request instead of using wildcards, which was then cached and applied to the subsequent request. When authorization caching is enabled, API Gateway caches the policy document returned by the authorizer for the duration of the TTL. If the policy lists a specific resource ARN instead of a wildcard, subsequent requests to different resources or methods using the same cache key will be evaluated against that cached policy and denied with a 403 Forbidden error.
Adım Adım Çözüm
Anahtar Kavram
API Gateway Lambda Authorizer Caching and Policy Evaluation