AWS Developer DVA-C02 · Development with AWS Services · medium
A web application hosted on https://app.example.com makes an XMLHttpRequest / fetch() POST call (with a custom Authorization: Bearer <jwt> header) directly from the user's browser to an Amazon API Gateway REST API hosted at https://api.example.org. The browser blocks the request with: Access to fetch at 'https://api.example.org' from origin 'https://app.example.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check. What must be configured on API Gateway to resolve this?
Published · Last updated · checked before publication — how we verify questions
Options
Answer: A. Enable CORS on API Gateway to handle OPTIONS preflight and return Access-Control-Allow-*
When a browser sends a cross-origin request with a custom header (Authorization) or non-simple method, it first sends an HTTP OPTIONS preflight request. Enabling CORS (Cross-Origin Resource Sharing) on the API Gateway resource configures an OPTIONS method (and adds Access-Control-Allow-Origin, Access-Control-Allow-Headers, and Access-Control-Allow-Methods headers to both the preflight and actual responses).
Why the other options are wrong
- B. Place the API Gateway inside a Private VPC Subnet with EndpointConfiguration: PRIVATE only — Making the API private prevents public browser clients from reaching it altogether.
- C. Enable AWS X-Ray active tracing on the API Gateway stage via tracingEnabled: true in SAM — X-Ray tracing records performance spans and does not emit browser CORS headers.
- D. Increase the API Gateway integration timeout from 29000 ms to 900000 ms on the POST route — API Gateway has a hard 29-second regional integration limit (unless using specific quota increases), and timeouts do not cause CORS preflight blocks.
More Development with AWS Services questions
- An Amazon API Gateway REST API fronts a legacy product-catalog backend that takes 800 ms per query. Because 90% of…
- A customer-facing checkout API built on AWS Lambda (Java 21 runtime) experiences a 3.2-second cold-start latency spike…
- An AWS Lambda function polls an Amazon SQS standard queue via an Event Source Mapping with a batch size of 10…
- An order-fulfillment workflow coordinates 6 sequential and parallel steps: reserve inventory, charge credit card…
- Five different AWS Lambda functions written in Python 3.12 share the same 45 MB internal cryptography and…
- A photo-sharing platform stores private user photos in an Amazon S3 bucket (Block Public Access = ON). When an…
- A financial ledger uses Amazon SQS FIFO (First-In-First-Out) queues (orders.fifo) to guarantee strict message ordering…
- A developer is designing indexes for an Amazon DynamoDB Orders table whose base primary key is CustomerId (Partition…
All Development with AWS Services questions and the topic overview →
AWS and Amazon Web Services are trademarks of Amazon.com, Inc. PrepIQ Hub is not affiliated with, endorsed by, or sponsored by Amazon Web Services.