AWS Certified Solutions Architect – Professional (SAP-C02) — Question 293

A company runs an unauthenticated static website (www.example.com) that includes a registration form for users. The website uses Amazon S3 for hosting and uses Amazon CloudFront as the content delivery network with AWS WAF configured. When the registration form is submitted, the website calls an Amazon API Gateway API endpoint that invokes an AWS Lambda function to process the payload and forward the payload to an external API call.

During testing, a solutions architect encounters a cross-origin resource sharing (CORS) error. The solutions architect confirms that the CloudFront distribution origin has the Access-Control-Allow-Origin header set to www.example.com.

What should the solutions architect do to resolve the error?

Answer options

Correct answer: C

Explanation

The CORS error occurs because the browser, loading resources from www.example.com, attempts to make an API call to a different domain (Amazon API Gateway) which does not return the required Access-Control-Allow-Origin header. Enabling CORS on the API Gateway API endpoint ensures that preflight OPTIONS requests and standard responses return the correct headers to authorize the cross-origin request. Configuring CORS on S3, WAF, or Lambda does not resolve the API Gateway integration handshake required by the browser.