Build CloudFront cache behavior configurations with path patterns, cache policies, and function associations in CloudFormation and Terraform.
No function associations configured. Add CloudFront Functions or Lambda@Edge triggers.
Path: /static/* Origin: S3-static-assets Protocol: redirect-to-https Methods: GET, HEAD Cache Policy: CachingOptimized (Recommended) Compress: Yes
# CloudFront Cache Behavior Configuration
# Add this under Distribution > DistributionConfig > CacheBehaviors
- PathPattern: "/static/*"
TargetOriginId: "S3-static-assets"
ViewerProtocolPolicy: redirect-to-https
AllowedMethods:
- GET
- HEAD
CachedMethods:
- GET
- HEAD
Compress: true
CachePolicyId: 658327ea-f89d-4fab-a63d-7e88639e58f6AWS recommends using managed cache policies (like CachingOptimized) instead of legacy forwarded values. Cache policies are reusable, easier to manage, and support newer features. Use custom TTLs only when you need fine-grained control over caching duration that managed policies do not provide.
Custom TTL settings are useful when your origin does not send Cache-Control headers, or when you need to override origin headers. MinTTL sets the floor, DefaultTTL applies when the origin has no cache headers, and MaxTTL caps how long objects stay cached regardless of origin headers.
CloudFront Functions run at 225+ edge locations, are limited to viewer events, and are ideal for lightweight transformations (URL rewrites, header manipulation). Lambda@Edge runs at regional edge caches, supports all four event types, and handles heavier processing (authentication, origin selection, image transformation).
The CloudFront Cache Behavior Builder helps you configure path-based caching rules for Amazon CloudFront distributions. Cache behaviors control how CloudFront handles requests matching specific URL path patterns, including which origin to forward to, cache key composition, TTL settings, viewer protocol policies, and Lambda@Edge or CloudFront Functions associations. This tool generates valid CloudFormation and Terraform configuration blocks.
Disclaimer: This tool runs entirely in your browser. No data is sent to our servers. Always verify outputs before using them in production. AWS, Azure, and GCP are trademarks of their respective owners.