DVA-C02 Development with AWS Services Practice Question
A developer is building a RESTful API using Amazon API Gateway and Lambda. The API should support CORS for a specific origin (https://example.com) and allow only GET and POST methods. Which configuration in the OPTIONS method response will satisfy these requirements?
⚠ Common exam trap
The trap here is that candidates often mistakenly include `OPTIONS` in the `Access-Control-Allow-Methods` header, thinking it must be listed because the preflight request uses that method, but the correct behavior is to only list the actual HTTP methods (GET, POST) that the API supports for the main request.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Access-Control-Allow-Origin: https://example.com, Access-Control-Allow-Methods: GET,POST
The OPTIONS method response must include the `Access-Control-Allow-Origin` header set to the specific origin `https://example.com` to restrict CORS access, and the `Access-Control-Allow-Methods` header must list only the allowed HTTP methods (`GET,POST`). The OPTIONS method itself is a preflight request and does not need to be listed in the allowed methods; it is automatically handled by the browser. This configuration satisfies the requirement of supporting CORS for a single origin and only GET and POST methods.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Access-Control-Allow-Origin: https://example.com, Access-Control-Allow-Methods: GET,POST
Why this is correct
This configuration correctly specifies `https://example.com` as the only permitted origin, adhering to the principle of least privilege for cross-origin requests. By listing `GET,POST` in `Access-Control-Allow-Methods`, the server explicitly informs the browser which actual HTTP methods are allowed for the resource, satisfying the preflight request's requirements without exposing unnecessary methods like `OPTIONS` itself.
- ✗
Access-Control-Allow-Origin: *, Access-Control-Allow-Methods: GET,POST,OPTIONS
Why it's wrong here
Using `*` for `Access-Control-Allow-Origin` is a significant security vulnerability, as it permits any domain to make cross-origin requests to the API, bypassing the same-origin policy without proper restrictions. Furthermore, explicitly including `OPTIONS` in `Access-Control-Allow-Methods` is redundant and incorrect; the browser initiates the `OPTIONS` preflight, and the server's response should indicate the methods allowed for the *actual* data requests, not the preflight method itself.
- ✗
Access-Control-Allow-Origin: https://example.com, Access-Control-Allow-Methods: GET,POST,OPTIONS
Why it's wrong here
While `Access-Control-Allow-Origin: https://example.com` correctly restricts access to a specific domain, including `OPTIONS` within the `Access-Control-Allow-Methods` header is unnecessary and technically imprecise. The browser sends an `OPTIONS` preflight request to determine permissions, and the server's response to this preflight should list only the methods (e.g., `GET`, `POST`) that the client is permitted to use for the subsequent actual request, not the preflight method itself.
- ✗
Access-Control-Allow-Origin: https://example.com, Access-Control-Allow-Headers: Content-Type
Why it's wrong here
This response is critically flawed because it omits the `Access-Control-Allow-Methods` header, which is essential for the browser to determine if the intended `GET` or `POST` requests are permitted cross-origin. Although `Access-Control-Allow-Origin` is correctly specified and `Access-Control-Allow-Headers` addresses custom headers, the absence of allowed methods will cause the browser to block the actual data request due to a CORS policy violation.
Quick reference
Cloud Service Model Comparison
| Model | You Manage | Provider Manages | Examples |
|---|---|---|---|
| IaaS | OS, runtime, apps, data | Hardware, hypervisor, networking | EC2, Azure VMs, GCP Compute Engine |
| PaaS | Apps and data | OS, runtime, middleware, hardware | Elastic Beanstalk, Azure App Service |
| SaaS | Data and settings only | Everything else | Microsoft 365, Salesforce, Workday |
| FaaS / Serverless | Function code only | Infra, scaling, runtime | Lambda, Azure Functions, Cloud Run |
| CaaS | Containers and apps | Kubernetes, OS, hardware | EKS, AKS, GKE |
Go deeper
Related to this question
About these practice questions
One of 724 original DVA-C02 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This DVA-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DVA-C02 exam.