AWS Certified Developer – Associate / Question #739 of 557

Question #739

A company built an API on AWS using Amazon CloudFront, Amazon API Gateway, and AWS Lambda. The API consistently receives at least five requests per second, and many users submit identical data via the POST method. The developer wants to cache these POST responses to reduce backend load and improve performance. Which solution meets these requirements?

A

Enable CloudFront caching with custom cache policies that include the POST method and relevant headers.

B

Modify the API Gateway stage settings to override the default cache behavior and enable caching for the POST method.

C

Store recent POST responses in the Lambda function's /tmp storage and configure the function to serve cached responses when possible.

D

Use Amazon ElastiCache to store POST responses and update the Lambda function to retrieve cached data from ElastiCache.

Explanation

Answer B is correct because Amazon API Gateway supports caching for HTTP methods like POST when explicitly configured. By overriding the default cache behavior in the API Gateway stage settings, the developer can enable caching for POST requests. This ensures identical POST requests (with the same data) are served from the cache, reducing backend Lambda invocations and improving latency.

Option A is incorrect because CloudFront primarily caches GET/HEAD methods by default. While custom cache policies can include POST, API Gateway's built-in caching is more direct and efficient for this scenario.
Option C is incorrect because Lambda's /tmp storage is ephemeral, not shared across instances, and unsuitable for consistent caching at scale.
Option D introduces unnecessary complexity by using ElastiCache, whereas API Gateway's native caching requires no code changes or additional services.

Key Points:
1. API Gateway allows caching for POST methods via stage settings.
2. Caching at the API layer reduces Lambda load.
3. Built-in caching is simpler than external solutions like ElastiCache.

Answer

The correct answer is: B