Soru

Zorluk: OrtaApplication Caching and Session State Management

An API designed with Amazon API Gateway and AWS Lambda retrieves product details from an Amazon DynamoDB table. The product data changes infrequently, but sudden traffic spikes occasionally cause throttling on the DynamoDB table. The developer wants to implement a caching solution at the API Gateway layer to minimize Lambda invocations and DynamoDB read load. Additionally, client applications must be able to occasionally bypass this cache to retrieve the most up-to-date data when a user manually refreshes the page. Which approach should the developer implement to meet these requirements?

  1. Enable API Gateway caching for the stage. Configure the API Gateway policy to allow cache invalidation, and instruct client applications to include the Cache-Control: max-age=0 header in their requests.Cevap
  2. B
    Implement an Amazon DynamoDB Accelerator (DAX) cluster in front of the DynamoDB table, and configure client applications to run a DynamoDB Scan operation with a filter expression when bypassing the cache.
  3. C
    Cache the product details within the AWS Systems Manager Parameter Store, and configure the Lambda function to retrieve the configurations from Parameter Store instead of DynamoDB on every invocation.
  4. D
    Store the product details in static variables within the AWS Lambda function's global execution context, and rely on execution context reuse to serve cached data or clear the variables on timeout.

Cevap

Enable API Gateway caching for the stage. Configure the API Gateway policy to allow cache invalidation, and instruct client applications to include the Cache-Control: max-age=0 header in their requests.
The correct option addresses the requirement to cache at the API Gateway layer to prevent Lambda invocations and DynamoDB reads. It leverages the native API Gateway caching feature and allows authorized clients to bypass the cache by passing the Cache-Control: max-age=0 header, which triggers a backend fetch.

Adım Adım Çözüm

1
Enable caching at the API Gateway stage level.
Requests are cached at the API Gateway layer, which reduces downstream Lambda invocations and DynamoDB read operations.
This directly targets the objective of caching at the entry point of the API, minimizing processing costs and backend resource consumption.
2
Configure permissions for cache invalidation.
API Gateway is configured to accept cache invalidation requests from authorized clients.
Security controls are necessary to prevent unauthorized clients from causing a denial-of-service (DoS) attack by constantly bypassing the cache.
3
Pass the Cache-Control: max-age=0 header in client requests.
The client request bypasses the API Gateway cache and fetches the fresh data from the backend.
The Cache-Control: max-age=0 header is the standard HTTP mechanism to request cache invalidation and retrieve live backend data.

Anahtar Kavram

API Gateway Caching and Cache Invalidation
Tahmini Süre:1m 30s
Bu soruyu puanla