A client-side Angular dashboard hosted on https://dashboard.cloudflow.net is integrated with an Amazon API Gateway REST API. When sending a PUT request to update user preferences, the browser console displays a CORS preflight blocked error. The API Gateway is configured with a Lambda proxy integration. Which two actions must the developer perform to resolve this issue? (Select TWO.)
- Configure the API Gateway resource to handle the OPTIONS preflight request and return the appropriate Access-Control-Allow-Methods and Access-Control-Allow-Origin headers.Cevap
- Update the backend Lambda function response payload to include the Access-Control-Allow-Origin header in the headers map.Cevap
- CAdd a cross-origin resource sharing (CORS) configuration on the Amazon S3 bucket hosting the Angular dashboard to allow requests from the API Gateway endpoint.
- DModify the Lambda function response to return a raw plain text string instead of a structured JSON payload.
- EConfigure a Lambda Authorizer on the OPTIONS method to authenticate the client during the preflight request.
Cevap
Configure the API Gateway resource to handle the OPTIONS preflight request and return the appropriate Access-Control headers, and update the backend Lambda function response payload to include the Access-Control-Allow-Origin header in the headers map.
Resolving a CORS issue with a Lambda proxy integration requires addressing two parts of the request cycle: the preflight handshake and the actual request. First, the OPTIONS preflight request must be enabled on the API Gateway resource to return the allowed methods, headers, and origin. Second, because it is a proxy integration, the backend Lambda function itself must return the Access-Control-Allow-Origin header in the response payload of the actual request.
Adım Adım Çözüm
Anahtar Kavram
Handling CORS in API Gateway with Lambda Proxy Integration