Skip to content

Cost Optimization Practices

Static website hosting on S3 and CloudFront is generally inexpensive, but costs can grow over time due to increased traffic, log storage, or inefficient caching. The following recommendations help optimize cost without reducing performance.


  1. Improve CloudFront caching efficiency.
    A higher cache hit rate reduces requests to S3 and lowers data transfer costs.

    Recommended settings:

    Setting Recommendation
    Cache policy CachingOptimized
    Minimum TTL ≥ 1 hour (longer if content rarely changes)
    Cache key Path + query (avoid headers/cookies unless needed)
    Serve stale on error Enabled

    For static sites that change infrequently, consider TTLs of several days or weeks.

  2. Reduce S3 storage and data transfer usage.

    Before uploading files to S3:

    • Minify CSS and JavaScript
    • Compress images (WebP or AVIF preferred)
    • Remove unused libraries or large assets

    Avoid hosting very large files directly (videos, ZIPs, large PDFs). If required:

    • Move them to storage classes like Intelligent-Tiering or Glacier
    • Use CloudFront signed URLs for controlled downloads
  3. Apply lifecycle rules to log buckets.

    CloudFront logs accumulate quickly. A recommended lifecycle policy:

    Action Timing
    Move to Glacier After 30–60 days
    Delete permanently After 1–2 years
  4. Choose the appropriate CloudFront pricing class to limit regional delivery.

    Price Class Regions Served Savings
    Price Class 100 US & Europe only 💰 Highest
    Price Class 200 US, Europe, Asia Moderate
    All Edge Locations Global No savings

    Select the option that matches where your users are located.

  5. Minimize costly cache invalidations.

    • Use file versioning (e.g., app.v2.js, styles.2024.css)
    • Avoid invalidating /* when possible
    • Invalidate only updated paths

    Versioning provides instant updates with zero invalidation cost.

  6. Avoid excessive logging.

    Logging can drive up S3 costs over time. Best practices:

    • Enable logging only where required
    • Use prefixes such as prod/ and staging/
    • Ensure lifecycle expiration rules are applied
  7. Use AWS Budgets to monitor cost changes early.

    Recommended budget alerts:

    Budget Type Threshold
    Monthly spend 80% and 100%
    Data transfer Alert on unusual spikes
    S3 storage Detect growing log volume

    Alerts can be delivered via email or SNS.

Summary of Cost Optimization Recommendations

Area Recommendation
CloudFront Maximize cache hit rate
S3 Compress static files; apply lifecycle policies
Logging Control retention and volume
Invalidation Use file versioning
Traffic regions Select appropriate pricing class