A client-side Next.js web portal hosted on https://portal.ecocharge.net sends a POST request to an Amazon API Gateway REST API configured with a Lambda Proxy integration to register new users. The API Gateway has CORS enabled on the resource. The web portal console shows a CORS error stating that the 'Access-Control-Allow-Origin' header is missing on the requested resource after the browser successfully completes the OPTIONS preflight request. Which of the following is the correct action to resolve this issue?
- AConfigure a custom Lambda Authorizer for the POST method and configure the authorizer's response payload to include the Access-Control-Allow-Origin header.
- BConfigure a CORS policy on the Amazon S3 bucket hosting the web portal's static assets to allow incoming traffic from the API Gateway endpoint.
- Modify the backend Lambda function's response to return a JSON object containing a 'headers' key with the 'Access-Control-Allow-Origin' header.Cevap
- DModify the Lambda function to return a plain text response body, and configure API Gateway's Integration Response to map the CORS headers.
Cevap
Modify the backend Lambda function's response to return a JSON object containing a 'headers' key with the 'Access-Control-Allow-Origin' header.
For a Lambda Proxy integration in Amazon API Gateway, the backend Lambda function is responsible for returning the complete response structure, including the status code, body, and all HTTP headers. While enabling CORS in the API Gateway console configures the preflight OPTIONS method, the actual method response (such as the POST response) must return the 'Access-Control-Allow-Origin' header directly within the Lambda function's JSON response payload.
Adım Adım Çözüm
Anahtar Kavram
Lambda Proxy Integration CORS Requirements
Tahmini Süre:1m 30s