A developer is building a serverless REST API using Amazon API Gateway and AWS Lambda. The API will be consumed by a web application hosted on a different domain. The developer needs to enable Cross-Origin Resource Sharing (CORS) for all HTTP methods. What is the most efficient way to achieve this?
Answer choices
Why each option matters
Good practice is not just finding the correct option. The wrong answers often show the exact trap the exam wants you to fall into.
Best answer
Enable CORS on the API Gateway resource using the 'Enable CORS' feature in the API Gateway console, which adds the OPTIONS method and appropriate headers.
API Gateway's built-in CORS feature automatically configures the OPTIONS method and adds the necessary headers (Access-Control-Allow-Origin, etc.) to the method responses and integration responses.
Distractor review
In the Lambda function code, add the 'Access-Control-Allow-Origin' header to every response.
While adding CORS headers in Lambda is necessary, it alone is not sufficient. The browser sends a preflight OPTIONS request that must be handled by API Gateway before the Lambda is invoked. Without an OPTIONS method configured, the preflight will fail.
Distractor review
Configure Amazon CloudFront in front of API Gateway to handle CORS.
CloudFront can forward CORS headers, but it does not replace the need to configure CORS on the API Gateway itself. This adds unnecessary complexity.
Distractor review
Set a bucket policy on the S3 bucket that hosts the web application to allow cross-origin requests.
Bucket policies are used to control access to S3 resources. They do not affect CORS behavior for API Gateway.
Common exam trap
Common exam trap: answer the scenario, not the keyword
Many certification questions include familiar terms but test a specific constraint. Read the exact wording before choosing an answer that is generally true but wrong for this case.
Technical deep dive
How to think about this question
This question should be treated as a scenario, not a definition check. Identify the problem, the constraint and the best action. Then compare each option against those facts.
KKey Concepts to Remember
- Read the scenario before looking for a memorised answer.
- Find the constraint that changes the correct option.
- Eliminate answers that are true in general but not in this case.
- Use explanations to understand the rule behind the answer.
TExam Day Tips
- Underline the problem statement mentally.
- Watch for words such as best, first, most likely and least administrative effort.
- Review why wrong options are wrong, not only why the correct option is correct.
Related practice questions
Related DVA-C02 practice-question pages
Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.
More questions from this exam
Keep practising from the same exam bank, or move into a focused topic page if this question exposed a weak area.
Question 1
A developer is building a REST API using Amazon API Gateway that will serve static content from an Amazon S3 bucket. The API should cache responses for frequently accessed objects to reduce latency. Which API Gateway feature should the developer enable?
Question 2
A developer is running a web application on multiple Amazon EC2 instances behind an Application Load Balancer (ALB). The application needs to store user session state that must be available across all instances. The session data is small and temporary but must survive individual instance failures. Which AWS service should the developer use to store this session state?
Question 3
A developer has an AWS Lambda function that processes messages from an Amazon SQS standard queue. The function is idempotent and currently has a batch size of 10. The developer wants to increase throughput and increases the batch size to 100. After the change, CloudWatch metrics show a significant increase in throttles and the queue backlog is growing. The function's reserved concurrency is set to 10. What is the most effective action to resolve the throttling and improve throughput?
Question 4
A developer is managing an application running on Amazon EC2 instances behind an Application Load Balancer. Users report that the application becomes unresponsive after several hours, and restarting the instance temporarily fixes the issue. The developer suspects a memory leak but cannot add custom instrumentation. Which AWS service can collect memory utilization metrics and help identify the memory leak with minimal configuration?
Question 5
A developer is building a serverless web application using AWS Lambda and Amazon DynamoDB. The application needs to perform complex aggregations on data stored in DynamoDB. Which AWS service should the developer use to perform these aggregations efficiently without reading all the data into Lambda?
Question 6
A developer has an Amazon S3 bucket containing private user documents. The application must generate a time-limited URL for users to download their own documents without requiring the users to have AWS credentials. Which solution should the developer use?
FAQ
Questions learners often ask
What does this DVA-C02 question test?
Read the scenario before looking for a memorised answer.
What is the correct answer to this question?
The correct answer is: Enable CORS on the API Gateway resource using the 'Enable CORS' feature in the API Gateway console, which adds the OPTIONS method and appropriate headers. — CORS can be enabled in API Gateway at the API level by configuring the Gateway Responses for 4XX and 5XX and adding the Access-Control-Allow-Origin header. However, the simplest way is to enable CORS from the API Gateway console or via the AWS CLI/API, which automatically adds the required OPTIONS method and the necessary headers to the integration responses. Option A (adding CORS headers in Lambda) is not sufficient because the browser sends a preflight OPTIONS request that must be handled by API Gateway before the Lambda is invoked. Option C (using a CloudFront distribution) is unnecessary overhead. Option D (setting a bucket policy) is irrelevant.
What should I do if I get this DVA-C02 question wrong?
Then try more questions from the same exam bank and focus on understanding why the wrong options are tempting.
Discussion
Sign in to join the discussion.