A frontend Single Page Application (SPA) hosted at `https://dashboard.company.local` makes a cross-origin `POST` request to an Amazon API Gateway REST API configured with a Lambda Proxy Integration. In the browser developer tools, the developer observes that the preflight `OPTIONS` request succeeds with a `200 OK` status code, but the subsequent `POST` request is blocked. The browser console displays: `Access-Control-Allow-Origin 'https://dashboard.company.local' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource`. Additionally, the network tab shows that the `POST` request received a `502 Bad Gateway` status code from API Gateway. Which of the following is the most accurate explanation for this behavior, and what corrective actions should the developer take to resolve both issues?
- The Lambda function returned a response payload that does not conform to the required JSON format for Lambda Proxy Integration, causing API Gateway to generate a default 502 Bad Gateway response that lacks the necessary CORS headers. The developer must update the Lambda function to return a structured JSON response containing statusCode, headers (including Access-Control-Allow-Origin), and body, and configure CORS headers on the API Gateway Gateway Responses for 5XX errors.Cevap
- BThe CORS headers were only configured on the mock OPTIONS method in API Gateway, which does not propagate to the actual POST integration. The developer must change the integration type to Lambda Custom Integration, configure a custom Integration Response to map CORS headers from the Lambda response, and enable CORS on the S3 bucket hosting the client SPA.
- CThe Lambda function is returning a raw string response because it is configured with Lambda Custom Integration, which requires the frontend to send custom preflight parameters. The developer should change the integration type to Lambda Proxy Integration because proxy integrations automatically inject the required Access-Control-Allow-Origin headers on behalf of the backend Lambda function.
- DThe request failed authentication at the API Gateway level because the custom Lambda Authorizer returned an invalid or expired IAM policy, triggering a 502 error. The developer must modify the Lambda Authorizer to return a policy that allows the OPTIONS method and configure the authorizer to bypass CORS validation for cross-origin client apps.