A client-side web application hosted on `https://portal.example.com` attempts to send a `DELETE` request to a resource on a REST API hosted on Amazon API Gateway. The API utilizes a Lambda Proxy Integration. The browser console displays an error stating that the request has been blocked by CORS policy because no 'Access-Control-Allow-Origin' header is present on the requested resource.
Which TWO actions must the developer take to resolve this issue?
- Enable CORS on the resource in the Amazon API Gateway console to configure the OPTIONS method.Cevap
- Update the backend Lambda function response to include the Access-Control-Allow-Origin header.Cevap
- CConfigure a CORS configuration rule on the Amazon S3 bucket hosting the web application to allow requests from the API Gateway domain.
- DConfigure the API Gateway integration to return a raw text response rather than a structured JSON payload.
- ECreate an API Gateway custom Lambda Authorizer that intercepts the preflight request and returns a policy allowing the origin.
Cevap
Enable CORS on the resource in the Amazon API Gateway console to configure the OPTIONS method, and update the backend Lambda function response to include the Access-Control-Allow-Origin header.
Resolving a CORS issue for a DELETE request requires two configuration steps. First, configuring the OPTIONS preflight method in API Gateway ensures that preflight CORS verification passes. Second, because Lambda Proxy Integration is utilized, the Lambda function itself must return the Access-Control-Allow-Origin header in its response envelope.
Adım Adım Çözüm
Anahtar Kavram
Handling CORS with Lambda Proxy Integrations requires configuring both the preflight OPTIONS method in API Gateway and the custom response headers inside the backend Lambda code.
Tahmini Süre:1m 30s