DVA-C03 practice question: Building APIs with API Gateway (1 of 2)
Development with AWS Services A free question from our original DVA-C03 practice exam. Try it, then open the answer to see why each option is right or wrong.
A pricing REST API in Amazon API Gateway returns a different price to each customer, based on the X-Customer-Id request header that the backend function reads.
To cut latency and backend calls, the team turned on stage-level caching for the prod stage with the default time-to-live. Since then, some customers have received another customer's prices.
The API must stay a single API and a single stage, and caching must stay on.
What should the developer change?
Choose one answer.
AA. Set the stage cache time-to-live to 0 seconds so that responses are never cached.
BB. Add X-Customer-Id as a method request header, and mark it as a cache key parameter on the method.
CC. Create one API stage for each customer, each with its own cache, and route every customer to their own stage.
DD. Create an API key and usage plan for each customer, so that API Gateway keeps a separate cache for each API key.
Show the answer and explanation
Answer: B
A. Wrong: A time-to-live of 0 turns caching off. Customers would stop seeing each other's prices, but the team would lose the latency and cost savings it turned caching on for.
B. Right: Correct. Cache key parameters decide which requests share a cached response. Adding the header as a key makes API Gateway cache each customer's response separately, so caching stays on.
C. Wrong: Separate caches would stop the leak, but one stage per customer breaks the single-stage requirement and adds a lot of operational work as the customer list grows.
D. Wrong: Usage plans control throttling and quotas for each API key. They do not partition the response cache, so the cache would still return one customer's response to another.
Explanation
API Gateway caches responses under a key made from the method's cache key parameters, and the default time-to-live is 300 seconds. Because the customer header was not a cache key, one customer's cached price was returned to others. Declaring the header as a cache key parameter fixes this while keeping caching on; a time-to-live of 0 disables caching, and API keys and usage plans do not change cache keys.
Want more on Building APIs with API Gateway? The 5 full-length practice sets have 10 more Building APIs with API Gateway questions, 390 in all, none of them in the free exam. One payment of $14.99, no subscription. See the practice sets →