Overview
Amazon CloudFront policies are configurations that dictate how content is cached, secured, and distributed. These policies allow for reusability and consistency across multiple behaviors or distributions, simplifying management and optimizing content delivery.
Types of CloudFront Policies
- Cache Policies
- Control caching behavior, including TTLs and the cache key.
- Origin Request Policies
- Manage how requests are forwarded to the origin.
- Response Headers Policies
- Add or modify HTTP headers in responses delivered to viewers.
Elaboration of Each Policy with Examples
1. Cache Policies
- Determines caching behavior at CloudFront edge locations.
- Controls:
- TTL (Time to Live) values.
- Cache key (which headers, query strings, or cookies are used to differentiate cached objects).
- Example:
- A website caches high-resolution product images:
- TTL = 1 month for static images.
- Cache key includes the query string
size (e.g., /images/product.jpg?size=large is cached separately from /images/product.jpg?size=small).
2. Origin Request Policies
- Specifies what information (headers, query strings, cookies) is forwarded to the origin.
- Reduces unnecessary traffic to the origin by limiting forwarded data.
- Example:
- A weather API forwards only the
location query string to the origin:
- Cache key =
/forecast?location=NYC.
- CloudFront doesn’t forward unrelated query strings like
user or device.
3. Response Headers Policies
- Adds, removes, or modifies HTTP response headers before delivering to the viewer.
- Common use cases include security headers or cache-control headers.