A developer is hosting a single-page web application in an Amazon S3 bucket. The application makes API calls to an Amazon API Gateway endpoint that is integrated with a Lambda function using Lambda Proxy integration. During testing, the browser console displays a CORS error stating that the preflight request was blocked because the Access-Control-Allow-Origin header is missing. Which two steps must the developer take to resolve this CORS error? (Select TWO.)
- Configure the API Gateway resource to handle the preflight OPTIONS request and return the Access-Control-Allow-Origin header.Cevap
- Modify the backend Lambda function to include the Access-Control-Allow-Origin header in its response JSON object.Cevap
- CConfigure a CORS policy on the Amazon S3 bucket hosting the frontend application to allow requests from the API Gateway endpoint.
- DChange the Lambda function to return a plain text string with the headers instead of a structured JSON response.
- EDeploy a custom Lambda authorizer to generate and inject the Access-Control-Allow-Origin header into the client request.
Cevap
Configure the API Gateway resource to handle the preflight OPTIONS request and modify the backend Lambda function to include the Access-Control-Allow-Origin header in its response JSON object.
To resolve CORS errors when using Amazon API Gateway with Lambda Proxy integration, two actions are required: enabling CORS on the API Gateway resource to handle the OPTIONS preflight request, and modifying the backend Lambda function to return the Access-Control-Allow-Origin header in its response JSON object.
Adım Adım Çözüm
Anahtar Kavram
Cross-Origin Resource Sharing (CORS) resolution in API Gateway Lambda Proxy integrations requires both the preflight OPTIONS response from API Gateway and the custom origin headers returned by the Lambda function.
Tahmini Süre:1m 0s