CloudFront Cost Optimizer
Quick start
- Price Class is the biggest single lever. If your viewers are
primarily in US/EU, switch
PriceClass_All to PriceClass_100
(US + Canada + Europe edge locations only). Saves 20-40% on
per-GB egress and per-request pricing. If you have viewers in
India/Middle East/Africa, use PriceClass_200. Reserve
PriceClass_All for genuinely global audiences including APAC
and South America.
- Cache hit ratio drives origin cost. Target > 90% for static
content. Every 1% below target costs you 1% more origin requests
and origin egress. Check via CloudFront
CacheHitRate metric; tune
cache policies (longer TTLs, drop query strings and cookies from
the cache key unless they vary the response).
- S3 origin + OAC is the cheapest origin. S3-to-CloudFront data
transfer is free in most regions. Custom origins behind ALB/EC2
pay EC2 data-transfer-out ($0.02/GB same-region) on every byte
CloudFront fetches. Route static assets to an S3 origin whenever
possible.
- Enable compression. Free feature. Reduces bytes-to-viewer 50-90%
(Brotli ~20% better than gzip on text). Reduces CloudFront egress
(you are billed on bytes-egressed) and improves user-perceived
latency. Requires
Compress: true on the cache behavior.
- Edge compute: prefer CloudFront Functions for lightweight logic.
Functions ($1/M invocations, sub-1ms runtime) handle header
manipulation, URL rewrites, token validation. Lambda@Edge
($0.60/M + compute-time billing) is for heavyweight logic that
needs the full Node/Python runtime and > 1MB memory. Misrouting
a header rewrite into Lambda@Edge costs 40x more per invocation.
Mindset
CloudFront cost is the product of three multiplicative drivers:
(1) requests (per-million pricing by Price Class region), (2)
bytes (per-GB egress from CloudFront to viewers, also tiered by
Price Class region), and (3) addons (WAF, Shield Advanced, Origin
Shield, Functions, Lambda@Edge). Each dimension compounds — a 90%
cache hit ratio cuts origin requests by 9x, which also cuts Origin
Shield GB, which also cuts origin-to-CloudFront egress. The cheapest
CloudFront bill is one where the cache does most of the work and the
origin is rarely touched.
Philosophy
Senior FinOps philosophy (price class as geography, hit ratio as policy, origin as architecture, 40x edge-compute decision) moved verbatim to references/advanced-patterns.md.
Load on demand when justifying a recommendation's economics.
Quick reference — verdict thresholds
| Observation (30-day window) |
Verdict |
Recommendation |
| PriceClass_All AND ≥ 95% viewers in US/EU |
OPPORTUNITY_FOUND (price class) |
Step 4 — switch to PriceClass_100 (saves 20-40%) |
| Cache hit ratio < 75% for static content |
OPPORTUNITY_FOUND (cache policy) |
Step 5 — drop unnecessary cache-key elements, raise TTLs |
| Custom origin (ALB/EC2) serving static assets |
OPPORTUNITY_FOUND (origin) |
Step 6 — migrate to S3 origin + OAC (free origin egress) |
| Compression disabled on text/image content |
OPPORTUNITY_FOUND (compression) |
Step 7 — enable Brotli/gzip (50-90% byte savings, free) |
| Origin Shield off AND ≥ 3 edge locations fetch same objects |
OPPORTUNITY_FOUND (Origin Shield) |
Step 8 — enable Origin Shield ($0.0125/GB, 95%+ origin load reduction) |
| Lambda@Edge used for header manipulation / URL rewrite |
OPPORTUNITY_FOUND (edge compute) |
Step 9 — migrate to CloudFront Functions (40x cheaper per invocation) |
| WAF with > 10 rules on a low-traffic distribution |
OPPORTUNITY_FOUND (security cost) |
Step 10 — consolidate rules or scope WAF to specific paths |
| Shield Advanced on a non-DDoS-prone workload |
OPPORTUNITY_FOUND (security cost) |
Step 10 — drop Shield Advanced, rely on Shield Standard (free) |
| All nine dimensions at cost-optimal config |
ALREADY_OPTIMAL |
None — continue monitoring |
| Distribution stopped for > 50% of window |
NEED_MORE_INFO |
Re-pull metrics over a stable running window |
See the ordered steps for edge cases (mixed-origin distributions,
field-level encryption, signed URLs, multi-distribution fleets).
Pre-flight: data gate (run before any optimization decision)
CloudFront optimization requires three data sources: distribution
config, CloudFront/CloudWatch metrics, and (optionally) Cost Explorer
billing data. Misclassifying a missing data source as "no problem"
produces overconfident recommendations.
Required data sources
Required data-source pull commands (config, 30-day metrics, Cost Explorer, viewer geography) moved verbatim to references/diagnostic-commands.md.
Run them before any optimization decision; apply the data-quality short-circuits below.
Data-quality short-circuits
| Condition |
Effect on optimization |
get-distribution-config returns Distribution.Deployed != Deployed |
NEED_MORE_INFO: distribution is mid-deploy. Wait until Status == Deployed, re-pull. |
| Observation window < 14 days |
NEED_MORE_INFO: workload may reflect atypical traffic (launch week, marketing campaign). Minimum 14 days; 30 days preferred. |
Distribution disabled (Enabled == false) for > 50% of window |
Metrics are zero. Re-pull after a stable 14-day enabled window. |
| CloudFront access logging disabled AND viewer geography unknown |
NEED_MORE_INFO for Price Class optimization: cannot confirm viewer geography. Cache/origin/compression dimensions can still be optimized. |
CacheHitRate metric absent (distribution < 24h old) |
NEED_MORE_INFO: insufficient samples. Wait 24-48h. |
WAF not associated (WebACLId empty) but caller says WAF is in use |
Cross-region WAF or WAF Classic mismatch. Re-query aws wafv2 list-web-acls --scope CLOUDFRONT --region us-east-1. |
Conflicting-data arbitration
When CloudFront metrics and Cost Explorer disagree (e.g., CloudFront
shows 5TB BytesDownloaded but Cost Explorer shows 7TB), trust Cost
Explorer for the bill, trust CloudFront for the operational
breakdown. Cost Explorer includes the free tier + taxes + WAF charges
that BytesDownloaded does not. Always sanity-check the projected
savings against the Cost Explorer actual before emitting the
recommendation.
Process — Optimization logic (apply in order)
Step 0: Non-obvious behaviours that change the recommendation
Step 0 gotchas (edge-location billing, per-edge hit ratio, managed policy fit, OAC/OAI, Accept-Encoding, single-region Shield, association billing, 1ms limit, WAF/Shield billing, Savings Bundle, MRAP, config parse gates) moved verbatim to references/advanced-patterns.md.
Load on demand when a recommendation routes away from the obvious choice.
Step 1: Validate input and data sufficiency
Data-sufficiency gates and partial-verdict output templates moved verbatim to references/advanced-patterns.md.
Verdict: NEED_MORE_INFO when CacheHitRate samples are absent or viewer geography is unknown; the other dimensions still emit.
Step 2: Cost Explorer reconciliation
Cost Explorer reconciliation command and USAGE_TYPE decode table moved verbatim to references/advanced-patterns.md.
Signal: -TF- APAC usage types with supposedly US-only viewers prove PriceClass_All serves from APAC edges.
Step 3: Distribution classification
Distribution classification table (seven shapes and their optimization emphasis) moved verbatim to references/advanced-patterns.md.
Use the shape to weight price class vs cache vs origin vs edge-compute emphasis.
Step 4: Price Class optimization
Price Class decision matrix and the APAC-egress proxy check moved verbatim to references/advanced-patterns.md.
Verdict: OPPORTUNITY_FOUND (price class) — >= 95% US/EU viewers on PriceClass_All -> PriceClass_100 saves 20-40%.
Step 5: Cache hit ratio optimization
Cache-policy probe commands, change table, and the UTM worked example moved verbatim to references/advanced-patterns.md.
Verdict: OPPORTUNITY_FOUND (cache policy) — static CacheHitRate < 75% means cache-key bloat or TTL too short.
Step 6: Origin optimization
Origin decision matrix and the custom-origin-to-S3 migration runbook moved verbatim to references/advanced-patterns.md.
Verdict: OPPORTUNITY_FOUND (origin) — custom origin serving static assets -> S3 + OAC saves $0.02/GB egress.
Step 7: Compression optimization
Compression probe, content-type decision matrix, and Accept-Encoding caveat moved verbatim to references/advanced-patterns.md.
Verdict: OPPORTUNITY_FOUND (compression) — Compress false on text/image content is a free 50-90% byte saving.
Step 8: Origin Shield optimization
Origin Shield break-even formula, decision matrix, and 3-edge math moved verbatim to references/advanced-patterns.md.
Verdict: OPPORTUNITY_FOUND (Origin Shield) — enable for custom origins and high request counts; skip low-volume S3.
Step 9: Edge compute optimization (Functions vs Lambda@Edge)
Edge-compute probe, decision matrix, cost math, and migration steps moved verbatim to references/advanced-patterns.md.
Verdict: OPPORTUNITY_FOUND (edge compute) — sub-1ms Lambda@Edge header/rewrite logic -> Functions; measure runtime first.
Step 10: Security cost optimization
WAF/Shield probes, security decision matrix, and Savings Bundle math moved verbatim to references/advanced-patterns.md.
Verdict: OPPORTUNITY_FOUND (security cost) — Shield Advanced on a non-DDoS-prone workload is $3,000/month recoverable.
Step 11: Impact estimation
Impact-estimation formula and 2026 pricing notes moved verbatim to references/advanced-patterns.md.
Output: sum per-dimension savings into ESTIMATED_SAVINGS (current minus projected monthly cost).
Step 12: Final verdict
The verdict is the worst-case (most-actionable) finding across all
nine dimensions:
- If ANY dimension recommends a change (price class, cache, origin,
compression, Shield, edge compute, security), verdict is
OPPORTUNITY_FOUND.
- If all dimensions pass AND the CloudFront Security Savings Bundle
has already been evaluated (whether adopted or rejected), verdict
is OPTIMIZED (when a change was applied this session) or
ALREADY_OPTIMAL (when no change was needed).
- If data is insufficient (no metrics, no viewer geography), verdict
is NEED_MORE_INFO for the affected dimensions.
Output format
TARGET: <distribution-id or distribution-description>
VERDICT: OPTIMIZED | OPPORTUNITY_FOUND | ALREADY_OPTIMAL
REASON: <1-2 sentences naming the recommendation and the supporting data>
RECOMMENDATION:
Current: PriceClass=<class>, origin=<type>, cache=<policy>,
compress=<bool>, shield=<bool>, edge_compute=<type>,
security=<waf+shield summary>
Proposed: <per-dimension list of changes>
Confidence: <HIGH/MEDIUM/LOW> — <one-line rationale>
ESTIMATED_SAVINGS:
Monthly (price class): $<amount>
Monthly (cache policy): $<amount>
Monthly (origin): $<amount>
Monthly (compression): $<amount>
Monthly (origin shield): $<amount>
Monthly (edge compute): $<amount>
Monthly (security): $<amount>
Annual total: $<amount>
Assumptions: <list (pricing region, 730h/month, etc.)>
MIGRATION_STEPS:
1. <specific action with CLI command>
2. <verification step>
CONFIRM: Before executing any state-changing CLI, emit and await operator
approval: "CONFIRM: About to <action> on <distribution-id>. Proceed?
(yes/no)"
Worked example — multi-dimension optimization
TARGET: E1ABC23DEF456G
VERDICT: OPPORTUNITY_FOUND
REASON: Distribution has PriceClass_All with 95% US/EU viewers,
CacheHitRate 62% on static content, compression disabled,
Lambda@Edge used for header manipulation, and Shield Advanced on
a marketing site. Five dimensions have actionable opportunities;
combined projected savings $4,820/month.
RECOMMENDATION:
Current: PriceClass=All, origin=mixed (S3+ALB), cache=CachingOptimized,
compress=false, shield=false, edge_compute=Lambda@Edge (1 assoc,
50ms p50), security=WAF 5 rules + Shield Advanced on this distribution
Proposed:
- PriceClass: PriceClass_100 (95% US/EU viewers)
- Cache policy: drop UTM query strings from cache key
- Origin: route /static/* to S3 origin + OAC
- Compress: enable Brotli + gzip
- Edge compute: migrate header manipulation to CloudFront Functions
- Security: drop Shield Advanced ($3K/month unjustified for
marketing site); keep WAF
Confidence: HIGH — viewer geography from CloudFront access logs,
Cost Explorer confirms APAC egress < 5%, cache-key analysis
shows UTMs as the primary fragmenter.
ESTIMATED_SAVINGS:
Monthly (price class): $420 (PriceClass_All → PriceClass_100 on
4.8TB egress + 800M requests)
Monthly (cache policy): $680 (CacheHitRate 62% → 90%, saves
~280GB origin egress + origin requests)
Monthly (origin): $56 ($0.02/GB on 2800GB static-asset egress
moved from ALB to S3)
Monthly (compression): $408 (Brotli on ~4800GB egress, ~85% byte
reduction on text subset ~3500GB)
Monthly (origin shield): $0 (Skipped — S3 origin already cheap,
Shield would cost more than it saves)
Monthly (edge compute): $212 (Lambda@Edge 800M invocations ×
$0.60/M = $480 → Functions $1/M ×
800M = $800... wait, Lambda is
cheaper here. Re-evaluate: keep
Lambda@Edge.)
Monthly (security): $3,000 (Drop Shield Advanced on this
non-DDoS-prone distribution)
Annual total: $57,012
Assumptions: us-east-1 pricing, 730h/month, 800M req/month, 4.8TB
egress/month, current Shield Advanced cost is per-distribution.
MIGRATION_STEPS:
1. Snapshot current distribution config:
aws cloudfront get-distribution-config --id E1ABC23DEF456G
--output json > backup-pre-optimization.json
2. Update PriceClass (single change, deploy, monitor 24h):
aws cloudfront update-distribution --id E1ABC23DEF456G \
--if-match <ETag> --distribution-config <updated-config-with-PriceClass_100>
3. Update cache policy (drop UTMs from cache key):
Create new cache policy with QueryStringBehavior="allExcept"
listing ["utm_source","utm_medium","utm_campaign",
"utm_term","utm_content"]
aws cloudfront create-cache-policy --cache-policy-config <json>
Update distribution to use new policy id on default behavior.
4. Enable compression on the default cache behavior:
Update DefaultCacheBehavior.Compress to true.
5. Create S3 origin with OAC for /static/* path:
aws cloudfront create-origin-access-control --origin-access-control-config <json>
aws s3 sync /var/www/static s3://static-bucket/ --delete
Update distribution origins + cache behavior to add /static/*
routing to S3 origin.
6. Drop Shield Advanced (after confirming SRT access not required):
aws shield delete-protection --protection-id <id>
7. Deploy each change separately, monitoring 24-48h between deploys
to isolate impact (Step 0 rule: never stack changes).
8. Post-deploy validation:
aws cloudfront get-distribution --id E1ABC23DEF456G --query
'Distribution.Status'
aws cloudwatch get-metric-statistics --namespace AWS/CloudFront
--metric-name CacheHitRate --dimensions Name=DistributionId,
Value=E1ABC23DEF456G --start-time ... --end-time ...
--period 3600 --statistics Average
CONFIRM: Before each state-changing CLI, emit and await:
"CONFIRM: About to <action> on E1ABC23DEF456G. Proceed? (yes/no)"
Do NOT run the CLI until the operator confirms. Stage changes one
dimension at a time; never batch all five in a single deploy.
Worked example — already optimal
Secondary worked example (ALREADY_OPTIMAL) moved verbatim to references/worked-examples.md.
Load on demand when emitting an ALREADY_OPTIMAL verdict.
Worked example — NEED_MORE_INFO (viewer geography unknown)
Secondary worked example (NEED_MORE_INFO, viewer geography unknown) moved verbatim to references/worked-examples.md.
Load on demand when the data gate blocks the Price Class dimension.
Verdict semantics — reconciling the verdict_shape
The verdict_shape declares three primary verdicts (OPTIMIZED | OPPORTUNITY_FOUND | ALREADY_OPTIMAL). The NEED_MORE_INFO verdict
is a pre-decision guard that appears when a specific dimension
cannot be evaluated.
| Verdict |
When to emit |
Position in workflow |
OPPORTUNITY_FOUND |
At least one of the nine dimensions has a concrete, savings-bearing recommendation. |
Primary — terminal for actionable findings. |
OPTIMIZED |
A change was applied and verified this session; metrics confirm the new config lands within target bands (cache hit > 90%, compression working). |
Primary — only emitted post-remediation. |
ALREADY_OPTIMAL |
All nine dimensions at cost-optimal config AND Security Savings Bundle evaluated (whether adopted or rejected with rationale). |
Primary — terminal for healthy findings. |
NEED_MORE_INFO |
Data gate failed for one or more dimensions: viewer geography unknown for Price Class, metrics absent for cache/origin, WAF/Shield state indeterminate. |
Pre-decision — emit per-dimension; the other dimensions can still emit OPPORTUNITY_FOUND. |
Rule: a partial NEED_MORE_INFO for one dimension does NOT block
OPPORTUNITY_FOUND on the other dimensions. Surface both — the
operator can apply the confirmed dimensions while collecting data
for the deferred one.
Cache-hit-ratio improvement targets (concrete formula)
Target hit-ratio formula and per-content-type target table moved verbatim to references/advanced-patterns.md.
Load on demand when setting per-content-type targets or quantifying the savings from closing the gap.
Error handling — CLI and data-source failures
API failure tables (CloudFront config, CloudWatch, Cost Explorer, WAF/Shield) and the aggregate retry policy moved verbatim to references/error-handling.md.
Load on demand when a data-source CLI call fails.
Anti-Patterns — NEVER do these things
NEVER recommend PriceClass_100 without confirming viewer
geography. APAC/South-America-only viewers will see significantly
higher latency routed through US/EU edges. The 20-40% savings is
not justified if it breaks the viewer experience for ≥ 5% of
traffic.
NEVER recommend PriceClass_100 for a live-video streaming
workload with global viewers. Latency-sensitive streaming requires
edge proximity; the savings from Price Class cannot offset viewer
churn from buffering.
NEVER recommend enabling Origin Shield on an S3 origin with low
request count (< 10M/month) without doing the break-even math.
Shield's $0.0125/GB exceeds the S3 GET savings on
low-request-volume distributions. Shield is a high-volume
optimization.
NEVER recommend migrating a Lambda@Edge function to CloudFront
Functions without measuring actual runtime. Functions have a 1ms
wall-clock limit. A 5ms Lambda@Edge function migrates to Functions
by truncating — the function will fail silently or error out.
NEVER recommend dropping Shield Advanced without confirming the
workload is not DDoS-prone. Public-facing commerce, gaming,
finance, and election-period government sites are DDoS targets;
the $3,000/month is insurance against a multi-million-dollar
outage.
NEVER recommend dropping WAF rules without checking CloudWatch
metrics for the rule. A rule with 0 blocks over 30 days is unused;
a rule with 1M blocks is actively protecting. Removing an active
rule opens a security hole.
NEVER recommend a single Price Class for a multi-tenant SaaS
workload without consulting per-tenant viewer geography. Tenant A
may be US-only; Tenant B may be APAC-majority. Per-tenant
distributions may be needed (multi-distribution architecture).
NEVER recommend changing multiple dimensions in a single deploy.
CloudFront updates are atomic per-deploy, but isolating impact
requires one dimension per deploy. A stacked deploy that produces
a cache-hit drop cannot be triaged ("was it the price class, the
cache policy, or the compression?").
NEVER trust get-distribution-config's LastModifiedTime as a
proxy for "config is current." An operator may have applied a
no-op change yesterday that bumped LastModifiedTime without
changing the optimization-relevant fields. Always diff against
the actual config values.
NEVER assume CloudFront access logging is enabled. Many
distributions are deployed without logging. Without logs, viewer
geography, error breakdowns, and per-edge cache-hit rates are
invisible. Always check DistributionConfig.Logging.Enabled.
NEVER recommend Origin Shield on a distribution where the origin
is in a different region from viewers AND cross-region transfer
exceeds $0.05/GB. Origin Shield adds a hop; in some
cross-region topologies it costs more than it saves.
NEVER recommend Brotli compression on responses that are already
Brotli-compressed at the origin. Double-compression is wasteful
and can corrupt the response. Check origin response headers for
Content-Encoding: br before enabling Brotli on the distribution.
NEVER recommend a CloudFront Security Savings Bundle commitment
beyond the steady-state CloudFront + WAF spend. The commitment is
a 1-year lock; committing above steady-state leaves you paying
for unused discount.
NEVER recommend migrating a custom origin to S3 without verifying
the content is genuinely static. Dynamic responses (HTML with
per-user personalization) cannot be served from S3 without
pre-generation. A "static" path that includes session-specific
content will break when moved to S3.
NEVER assume the AWS-managed CachingOptimized cache policy is
optimal for all static content. It sets TTL=31536000 (1 year);
content that changes weekly will be stale for up to a year unless
invalidated. Use a custom policy with shorter TTL OR add
invalidation hooks to the deploy pipeline.
NEVER recommend Lambda@Edge for sub-1ms logic that could run as
a CloudFront Function. The 40x cost differential is significant
at high invocation counts. Always check the runtime profile
before choosing Lambda@Edge.
NEVER recommend enabling compression on SSE / streaming responses.
Compression breaks the chunk-transfer semantics and causes viewer-
side buffering failures. Compression is for finite-size responses
only.
NEVER skip the post-deploy validation step. CloudFront config
changes are eventually-consistent; CacheHitRate and Requests
metrics take 5-15 minutes to reflect the new config. Verify
with get-distribution --query 'Distribution.Status' and
CloudWatch before declaring the optimization complete.
NEVER recommend the CloudFront Security Savings Bundle without
modeling the breakage cost. The bundle is a 1-year commit; if
traffic drops (e.g., seasonal site), the commit is still owed.
Quick navigation
| You want to... |
Jump to |
| Decide Price Class |
Step 4 — Price Class optimization |
| Diagnose low cache hit ratio |
Step 5 — Cache hit ratio optimization |
| Decide S3 origin vs custom origin |
Step 6 — Origin optimization |
| Decide whether to enable compression |
Step 7 — Compression optimization |
| Decide whether Origin Shield is worth it |
Step 8 — Origin Shield optimization |
| Decide Lambda@Edge vs CloudFront Functions |
Step 9 — Edge compute optimization |
| Decide whether to keep Shield Advanced |
Step 10 — Security cost optimization |
| Build the savings projection |
Step 11 — Impact estimation |
| Handle missing data |
Step 1 — Validate input and data sufficiency |
| Handle API errors |
Error handling section |
Expert heuristic — the 60-second triage
The 60-second triage (six checks on config, hit rate, CE usage types, Lambda@Edge, Shield, WAF rules) moved verbatim to references/advanced-patterns.md.
Run it before deep-diving any single dimension.
Pre-flight safety checks (run before any remediation CLI)
Pre-flight safety checks (CONFIRMATION GATE, snapshot, one-dimension-per-deploy, fleet batching, invalidation cost, replica deletion) moved verbatim to references/diagnostic-commands.md.
Load them before emitting any remediation CLI.
Remediation guidance
Per-dimension remediation CLI sequences (price class, cache policy, compression, origin, shield, edge compute, security, already-optimal) moved verbatim to references/error-handling.md.
Load on demand when writing the MIGRATION_STEPS block.
Deep reference: CloudFront pricing and limit cheat sheet
Pricing tiers, quota reference, and the Functions-vs-Lambda@Edge capability matrix moved verbatim to references/cloudfront-pricing-reference.md.
Load on demand for pricing math and limit checks.
Recent AWS features (2024-2026)
Recent AWS features (2024-2026) moved verbatim to references/advanced-patterns.md.
Load on demand when scoping Savings Bundle, OAC, KeyValueStore, continuous deployment, MRAP, or VPC origins.
References (load on demand)
- references/cloudfront-pricing-reference.md — pricing matrix, Origin Shield break-even, WAF/Shield pricing; now also the pricing cheat sheet (tiers, quotas, Functions vs Lambda@Edge) moved from SKILL.md
- references/advanced-patterns.md — philosophy, Step 0 gotchas, Step 1-11 deep dives (matrices, probes, worked math), hit-ratio targets, 60-second triage, recent AWS features moved from SKILL.md
- references/diagnostic-commands.md — required data-source pulls and pre-flight safety checks moved from SKILL.md
- references/error-handling.md — CLI/data-source failure tables, retry policy, and per-dimension remediation CLI moved from SKILL.md
- references/worked-examples.md — ALREADY_OPTIMAL and NEED_MORE_INFO worked examples moved from SKILL.md
Domain
AWS CloudOps / CloudFront CDN Cost Optimization, FinOps & Edge.
AWS documentation
1---2name: cloudfront-cost-optimizer3description: Optimizes CloudFront distribution costs across nine cost dimensions — Price Class (PriceClass_100 vs PriceClass_200 vs PriceClass_All, where PriceClass_100 saves 20-40% when viewers are US/EU-only), cache hit ratio (target >90% for static content via longer TTLs and minimal cache key), origin choice (S3 + OAC is cheapest; custom origins incur $0.02/GB egress), compression (free, 50-90% byte savings via Brotli/gzip), Origin Shield ($0.0125/GB, cuts origin load 95%+), CloudFront Functions ($1/M) vs Lambda@Edge ($0.60/M + compute), security cost (WAF $5/rule + $1/M req, Shield Standard free, Shield Advanced $3K/mo), data-transfer matrix, and impact estimation. Emits OPPORTUNITY_FOUND with per-dimension savings, OPTIMIZED, or ALREADY_OPTIMAL. Use when reviewing CloudFront bills, triaging data-transfer charges, choosing Functions vs Lambda@Edge, or evaluating Origin Shield break-even.4license: Apache-2.05compatibility: Agent runtime that reads SKILL.md (Claude Code, Cursor, Windsurf, Codex, Gemini). Offline recommendation-document classification works from pasted distribution config and CloudFront metrics. Live-account optimization uses aws cloudfront get-distribution-config, get-distribution-metrics, list-cache-policies, list-origin-request -policies, aws cloudwatch get-metric-statistics (CacheHitRate, Requests, BytesDownloaded, OriginLatency), aws wafv2 list-web-acls, aws ce get-cost-and-usage, and aws...6metadata:7 source: https://skillmd.com/skills/jhkchan/cloudfront-cost-optimizer8 domain: aws-cloudops9 complexity: medium10 requires_llm: 'true'11 phase: '3'12 supports_pipeline: 'true'13 entry_point: 'false'14 family: Networking15 task_type: optimize16 skill_class: capability17 lifecycle_status: active18 verdict_shape: OPTIMIZED | OPPORTUNITY_FOUND | ALREADY_OPTIMAL19 when_to_use: Optimizing CloudFront distribution costs, reviewing Price Class against viewer geography, raising cache hit ratio, choosing between S3 origin and custom origin, evaluating Origin Shield break-even, deciding between CloudFront Functions and Lambda@Edge, sizing the WAF rule budget, or building a monthly CloudFront cost projection.20 when_not_to_use: Troubleshooting a 5xx or cache-miss root cause (use cloudfront-cache-troubleshooter), auditing the distribution security posture (use cloudfront-distribution-auditor for OAC, field-level encryption, IAM), deploying a new distribution (use cloudfront-distribution-deployer), S3 bucket lifecycle optimization (use s3-lifecycle-optimizer), or EC2/ALB data-transfer optimization that does not involve CloudFront (use data-transfer-optimizer). This skill focuses on cost optimization of an existing CloudFront distribution, not on deployment, security audit, or generic data-transfer patterns.21 activation_triggers: optimize CloudFront cost, CloudFront monthly bill, PriceClass recommendation, CloudFront cache hit ratio, Origin Shield break-even, CloudFront Functions vs Lambda@Edge, S3 origin vs custom origin cost, CloudFront data transfer cost, CloudFront WAF cost, CDN cost optimization, reduce CloudFront bill, Brotli compression CloudFront, CloudFront PriceClass_All, cache policy TTL optimization, FinOps CDN review22 invocation_schema: 'Input: either (a) a distribution identifier + live-account context, (b) a pasted distribution configuration (origins, default_cache_behavior including price_class, viewer_protocol_policy, trusted_key_groups, lambda_function_associations, cache_policy_id, origin_request_policy_id), OR (c) aggregated CloudFront usage (monthly requests, GB transferred, edge regions, cache hit ratio). Output: a deterministic TARGET / VERDICT / REASON / RECOMMENDATION / ESTIMATED_SAVINGS / MIGRATION_STEPS block per distribution, where VERDICT ∈ {OPTIMIZED, OPPORTUNITY_FOUND, ALREADY_OPTIMAL} and RECOMMENDATION lists the per-dimension actions (price_class, cache_policy, origin, compression, origin_shield, edge_compute, security).'23 invocation_example: "# Minimal valid input (offline config classification):\nDistributionId: E1ABC23DEF456G\nRegion: us-east-1 (distribution); viewers primarily US + EU\nPriceClass: PriceClass_All\nOrigins:\n - S3 origin with OAC: s3-prod-assets (us-east-1)\n - Custom origin: ALB in us-east-1 (app.example.com)\nDefault cache behavior:\n Target origin: ALB custom origin\n Cache policy: CachingOptimized (TTL 31536000)\n Origin request policy: AllViewerExceptInternal\n Viewer protocol policy: redirect-to-https\n Compress: false\n Lambda@Edge associations: 1 viewer-request (Node 18, 50ms avg)\nCloudFront Functions associations: 0\nWAF: 5 rules, ~500M requests/month\nMetrics (last 30 days):\n CacheHitRate: 62%\n Requests: 800,000,000\n BytesDownloaded: 4,800 GB\n OriginLatency: 250ms p50\nEmit the standard optimization block (TARGET, VERDICT, REASON,\nRECOMMENDATION, ESTIMATED_SAVINGS, MIGRATION_STEPS)."24 version: 0.1.025 author: Jacky Chan — AWS Community Builder26 keywords: CloudFront, CDN, Price Class, PriceClass_100, cache hit ratio, Origin Shield, Origin Access Control, OAC, compression, Brotli, gzip, CloudFront Functions, Lambda@Edge, WAF, Shield Advanced, data transfer, S3 origin, custom origin, cache policy, origin request policy, TTL, FinOps, edge computing27 tags: cloudfront, networking, cost-optimization, finops, cdn, edge28---2930# CloudFront Cost Optimizer3132## Quick start3334- **Price Class is the biggest single lever.** If your viewers are35 primarily in US/EU, switch `PriceClass_All` to `PriceClass_100`36 (US + Canada + Europe edge locations only). Saves 20-40% on37 per-GB egress and per-request pricing. If you have viewers in38 India/Middle East/Africa, use `PriceClass_200`. Reserve39 `PriceClass_All` for genuinely global audiences including APAC40 and South America.41- **Cache hit ratio drives origin cost.** Target > 90% for static42 content. Every 1% below target costs you 1% more origin requests43 and origin egress. Check via CloudFront `CacheHitRate` metric; tune44 cache policies (longer TTLs, drop query strings and cookies from45 the cache key unless they vary the response).46- **S3 origin + OAC is the cheapest origin.** S3-to-CloudFront data47 transfer is free in most regions. Custom origins behind ALB/EC248 pay EC2 data-transfer-out ($0.02/GB same-region) on every byte49 CloudFront fetches. Route static assets to an S3 origin whenever50 possible.51- **Enable compression.** Free feature. Reduces bytes-to-viewer 50-90%52 (Brotli ~20% better than gzip on text). Reduces CloudFront egress53 (you are billed on bytes-egressed) and improves user-perceived54 latency. Requires `Compress: true` on the cache behavior.55- **Edge compute: prefer CloudFront Functions for lightweight logic.**56 Functions ($1/M invocations, sub-1ms runtime) handle header57 manipulation, URL rewrites, token validation. Lambda@Edge58 ($0.60/M + compute-time billing) is for heavyweight logic that59 needs the full Node/Python runtime and > 1MB memory. Misrouting60 a header rewrite into Lambda@Edge costs 40x more per invocation.6162## Mindset6364CloudFront cost is the product of three multiplicative drivers:65(1) **requests** (per-million pricing by Price Class region), (2)66**bytes** (per-GB egress from CloudFront to viewers, also tiered by67Price Class region), and (3) **addons** (WAF, Shield Advanced, Origin68Shield, Functions, Lambda@Edge). Each dimension compounds — a 90%69cache hit ratio cuts origin requests by 9x, which also cuts Origin70Shield GB, which also cuts origin-to-CloudFront egress. The cheapest71CloudFront bill is one where the cache does most of the work and the72origin is rarely touched.7374## Philosophy7576Senior FinOps philosophy (price class as geography, hit ratio as policy, origin as architecture, 40x edge-compute decision) moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).77Load on demand when justifying a recommendation's economics.7879## Quick reference — verdict thresholds8081| Observation (30-day window) | Verdict | Recommendation |82|---|---|---|83| PriceClass_All AND ≥ 95% viewers in US/EU | **OPPORTUNITY_FOUND** (price class) | Step 4 — switch to PriceClass_100 (saves 20-40%) |84| Cache hit ratio < 75% for static content | **OPPORTUNITY_FOUND** (cache policy) | Step 5 — drop unnecessary cache-key elements, raise TTLs |85| Custom origin (ALB/EC2) serving static assets | **OPPORTUNITY_FOUND** (origin) | Step 6 — migrate to S3 origin + OAC (free origin egress) |86| Compression disabled on text/image content | **OPPORTUNITY_FOUND** (compression) | Step 7 — enable Brotli/gzip (50-90% byte savings, free) |87| Origin Shield off AND ≥ 3 edge locations fetch same objects | **OPPORTUNITY_FOUND** (Origin Shield) | Step 8 — enable Origin Shield ($0.0125/GB, 95%+ origin load reduction) |88| Lambda@Edge used for header manipulation / URL rewrite | **OPPORTUNITY_FOUND** (edge compute) | Step 9 — migrate to CloudFront Functions (40x cheaper per invocation) |89| WAF with > 10 rules on a low-traffic distribution | **OPPORTUNITY_FOUND** (security cost) | Step 10 — consolidate rules or scope WAF to specific paths |90| Shield Advanced on a non-DDoS-prone workload | **OPPORTUNITY_FOUND** (security cost) | Step 10 — drop Shield Advanced, rely on Shield Standard (free) |91| All nine dimensions at cost-optimal config | **ALREADY_OPTIMAL** | None — continue monitoring |92| Distribution stopped for > 50% of window | **NEED_MORE_INFO** | Re-pull metrics over a stable running window |9394See the ordered steps for edge cases (mixed-origin distributions,95field-level encryption, signed URLs, multi-distribution fleets).9697## Pre-flight: data gate (run before any optimization decision)9899CloudFront optimization requires three data sources: distribution100config, CloudFront/CloudWatch metrics, and (optionally) Cost Explorer101billing data. Misclassifying a missing data source as "no problem"102produces overconfident recommendations.103104### Required data sources105106Required data-source pull commands (config, 30-day metrics, Cost Explorer, viewer geography) moved verbatim to [references/diagnostic-commands.md](references/diagnostic-commands.md).107Run them before any optimization decision; apply the data-quality short-circuits below.108109### Data-quality short-circuits110111| Condition | Effect on optimization |112|---|---|113| `get-distribution-config` returns `Distribution.Deployed` != `Deployed` | **NEED_MORE_INFO**: distribution is mid-deploy. Wait until `Status == Deployed`, re-pull. |114| Observation window < 14 days | **NEED_MORE_INFO**: workload may reflect atypical traffic (launch week, marketing campaign). Minimum 14 days; 30 days preferred. |115| Distribution disabled (`Enabled == false`) for > 50% of window | Metrics are zero. Re-pull after a stable 14-day enabled window. |116| CloudFront access logging disabled AND viewer geography unknown | **NEED_MORE_INFO** for Price Class optimization: cannot confirm viewer geography. Cache/origin/compression dimensions can still be optimized. |117| `CacheHitRate` metric absent (distribution < 24h old) | **NEED_MORE_INFO**: insufficient samples. Wait 24-48h. |118| WAF not associated (`WebACLId` empty) but caller says WAF is in use | Cross-region WAF or WAF Classic mismatch. Re-query `aws wafv2 list-web-acls --scope CLOUDFRONT --region us-east-1`. |119120### Conflicting-data arbitration121122When CloudFront metrics and Cost Explorer disagree (e.g., CloudFront123shows 5TB BytesDownloaded but Cost Explorer shows 7TB), trust Cost124Explorer for the bill, trust CloudFront for the operational125breakdown. Cost Explorer includes the free tier + taxes + WAF charges126that BytesDownloaded does not. Always sanity-check the projected127savings against the Cost Explorer actual before emitting the128recommendation.129130## Process — Optimization logic (apply in order)131132### Step 0: Non-obvious behaviours that change the recommendation133134Step 0 gotchas (edge-location billing, per-edge hit ratio, managed policy fit, OAC/OAI, Accept-Encoding, single-region Shield, association billing, 1ms limit, WAF/Shield billing, Savings Bundle, MRAP, config parse gates) moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).135Load on demand when a recommendation routes away from the obvious choice.136137### Step 1: Validate input and data sufficiency138139Data-sufficiency gates and partial-verdict output templates moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).140Verdict: NEED_MORE_INFO when CacheHitRate samples are absent or viewer geography is unknown; the other dimensions still emit.141142### Step 2: Cost Explorer reconciliation143144Cost Explorer reconciliation command and USAGE_TYPE decode table moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).145Signal: `-TF-` APAC usage types with supposedly US-only viewers prove PriceClass_All serves from APAC edges.146147### Step 3: Distribution classification148149Distribution classification table (seven shapes and their optimization emphasis) moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).150Use the shape to weight price class vs cache vs origin vs edge-compute emphasis.151152### Step 4: Price Class optimization153154Price Class decision matrix and the APAC-egress proxy check moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).155Verdict: OPPORTUNITY_FOUND (price class) — >= 95% US/EU viewers on PriceClass_All -> PriceClass_100 saves 20-40%.156157### Step 5: Cache hit ratio optimization158159Cache-policy probe commands, change table, and the UTM worked example moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).160Verdict: OPPORTUNITY_FOUND (cache policy) — static CacheHitRate < 75% means cache-key bloat or TTL too short.161162### Step 6: Origin optimization163164Origin decision matrix and the custom-origin-to-S3 migration runbook moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).165Verdict: OPPORTUNITY_FOUND (origin) — custom origin serving static assets -> S3 + OAC saves $0.02/GB egress.166167### Step 7: Compression optimization168169Compression probe, content-type decision matrix, and Accept-Encoding caveat moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).170Verdict: OPPORTUNITY_FOUND (compression) — Compress false on text/image content is a free 50-90% byte saving.171172### Step 8: Origin Shield optimization173174Origin Shield break-even formula, decision matrix, and 3-edge math moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).175Verdict: OPPORTUNITY_FOUND (Origin Shield) — enable for custom origins and high request counts; skip low-volume S3.176177### Step 9: Edge compute optimization (Functions vs Lambda@Edge)178179Edge-compute probe, decision matrix, cost math, and migration steps moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).180Verdict: OPPORTUNITY_FOUND (edge compute) — sub-1ms Lambda@Edge header/rewrite logic -> Functions; measure runtime first.181182### Step 10: Security cost optimization183184WAF/Shield probes, security decision matrix, and Savings Bundle math moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).185Verdict: OPPORTUNITY_FOUND (security cost) — Shield Advanced on a non-DDoS-prone workload is $3,000/month recoverable.186187### Step 11: Impact estimation188189Impact-estimation formula and 2026 pricing notes moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).190Output: sum per-dimension savings into ESTIMATED_SAVINGS (current minus projected monthly cost).191192### Step 12: Final verdict193194The verdict is the worst-case (most-actionable) finding across all195nine dimensions:196197- If ANY dimension recommends a change (price class, cache, origin,198 compression, Shield, edge compute, security), verdict is199 **OPPORTUNITY_FOUND**.200- If all dimensions pass AND the CloudFront Security Savings Bundle201 has already been evaluated (whether adopted or rejected), verdict202 is **OPTIMIZED** (when a change was applied this session) or203 **ALREADY_OPTIMAL** (when no change was needed).204- If data is insufficient (no metrics, no viewer geography), verdict205 is **NEED_MORE_INFO** for the affected dimensions.206207## Output format208209```text210TARGET: <distribution-id or distribution-description>211VERDICT: OPTIMIZED | OPPORTUNITY_FOUND | ALREADY_OPTIMAL212REASON: <1-2 sentences naming the recommendation and the supporting data>213RECOMMENDATION:214 Current: PriceClass=<class>, origin=<type>, cache=<policy>,215 compress=<bool>, shield=<bool>, edge_compute=<type>,216 security=<waf+shield summary>217 Proposed: <per-dimension list of changes>218 Confidence: <HIGH/MEDIUM/LOW> — <one-line rationale>219ESTIMATED_SAVINGS:220 Monthly (price class): $<amount>221 Monthly (cache policy): $<amount>222 Monthly (origin): $<amount>223 Monthly (compression): $<amount>224 Monthly (origin shield): $<amount>225 Monthly (edge compute): $<amount>226 Monthly (security): $<amount>227 Annual total: $<amount>228 Assumptions: <list (pricing region, 730h/month, etc.)>229MIGRATION_STEPS:230 1. <specific action with CLI command>231 2. <verification step>232CONFIRM: Before executing any state-changing CLI, emit and await operator233 approval: "CONFIRM: About to <action> on <distribution-id>. Proceed?234 (yes/no)"235```236237### Worked example — multi-dimension optimization238239```text240TARGET: E1ABC23DEF456G241VERDICT: OPPORTUNITY_FOUND242REASON: Distribution has PriceClass_All with 95% US/EU viewers,243 CacheHitRate 62% on static content, compression disabled,244 Lambda@Edge used for header manipulation, and Shield Advanced on245 a marketing site. Five dimensions have actionable opportunities;246 combined projected savings $4,820/month.247RECOMMENDATION:248 Current: PriceClass=All, origin=mixed (S3+ALB), cache=CachingOptimized,249 compress=false, shield=false, edge_compute=Lambda@Edge (1 assoc,250 50ms p50), security=WAF 5 rules + Shield Advanced on this distribution251 Proposed:252 - PriceClass: PriceClass_100 (95% US/EU viewers)253 - Cache policy: drop UTM query strings from cache key254 - Origin: route /static/* to S3 origin + OAC255 - Compress: enable Brotli + gzip256 - Edge compute: migrate header manipulation to CloudFront Functions257 - Security: drop Shield Advanced ($3K/month unjustified for258 marketing site); keep WAF259 Confidence: HIGH — viewer geography from CloudFront access logs,260 Cost Explorer confirms APAC egress < 5%, cache-key analysis261 shows UTMs as the primary fragmenter.262ESTIMATED_SAVINGS:263 Monthly (price class): $420 (PriceClass_All → PriceClass_100 on264 4.8TB egress + 800M requests)265 Monthly (cache policy): $680 (CacheHitRate 62% → 90%, saves266 ~280GB origin egress + origin requests)267 Monthly (origin): $56 ($0.02/GB on 2800GB static-asset egress268 moved from ALB to S3)269 Monthly (compression): $408 (Brotli on ~4800GB egress, ~85% byte270 reduction on text subset ~3500GB)271 Monthly (origin shield): $0 (Skipped — S3 origin already cheap,272 Shield would cost more than it saves)273 Monthly (edge compute): $212 (Lambda@Edge 800M invocations ×274 $0.60/M = $480 → Functions $1/M ×275 800M = $800... wait, Lambda is276 cheaper here. Re-evaluate: keep277 Lambda@Edge.)278 Monthly (security): $3,000 (Drop Shield Advanced on this279 non-DDoS-prone distribution)280 Annual total: $57,012281 Assumptions: us-east-1 pricing, 730h/month, 800M req/month, 4.8TB282 egress/month, current Shield Advanced cost is per-distribution.283MIGRATION_STEPS:284 1. Snapshot current distribution config:285 aws cloudfront get-distribution-config --id E1ABC23DEF456G286 --output json > backup-pre-optimization.json287 2. Update PriceClass (single change, deploy, monitor 24h):288 aws cloudfront update-distribution --id E1ABC23DEF456G \289 --if-match <ETag> --distribution-config <updated-config-with-PriceClass_100>290 3. Update cache policy (drop UTMs from cache key):291 Create new cache policy with QueryStringBehavior="allExcept"292 listing ["utm_source","utm_medium","utm_campaign",293 "utm_term","utm_content"]294 aws cloudfront create-cache-policy --cache-policy-config <json>295 Update distribution to use new policy id on default behavior.296 4. Enable compression on the default cache behavior:297 Update DefaultCacheBehavior.Compress to true.298 5. Create S3 origin with OAC for /static/* path:299 aws cloudfront create-origin-access-control --origin-access-control-config <json>300 aws s3 sync /var/www/static s3://static-bucket/ --delete301 Update distribution origins + cache behavior to add /static/*302 routing to S3 origin.303 6. Drop Shield Advanced (after confirming SRT access not required):304 aws shield delete-protection --protection-id <id>305 7. Deploy each change separately, monitoring 24-48h between deploys306 to isolate impact (Step 0 rule: never stack changes).307 8. Post-deploy validation:308 aws cloudfront get-distribution --id E1ABC23DEF456G --query309 'Distribution.Status'310 aws cloudwatch get-metric-statistics --namespace AWS/CloudFront311 --metric-name CacheHitRate --dimensions Name=DistributionId,312 Value=E1ABC23DEF456G --start-time ... --end-time ...313 --period 3600 --statistics Average314CONFIRM: Before each state-changing CLI, emit and await:315 "CONFIRM: About to <action> on E1ABC23DEF456G. Proceed? (yes/no)"316 Do NOT run the CLI until the operator confirms. Stage changes one317 dimension at a time; never batch all five in a single deploy.318```319320### Worked example — already optimal321322Secondary worked example (ALREADY_OPTIMAL) moved verbatim to [references/worked-examples.md](references/worked-examples.md).323Load on demand when emitting an ALREADY_OPTIMAL verdict.324325### Worked example — NEED_MORE_INFO (viewer geography unknown)326327Secondary worked example (NEED_MORE_INFO, viewer geography unknown) moved verbatim to [references/worked-examples.md](references/worked-examples.md).328Load on demand when the data gate blocks the Price Class dimension.329330## Verdict semantics — reconciling the verdict_shape331332The `verdict_shape` declares three primary verdicts (`OPTIMIZED |333OPPORTUNITY_FOUND | ALREADY_OPTIMAL`). The `NEED_MORE_INFO` verdict334is a pre-decision guard that appears when a specific dimension335cannot be evaluated.336337| Verdict | When to emit | Position in workflow |338|---|---|---|339| `OPPORTUNITY_FOUND` | At least one of the nine dimensions has a concrete, savings-bearing recommendation. | Primary — terminal for actionable findings. |340| `OPTIMIZED` | A change was applied and verified this session; metrics confirm the new config lands within target bands (cache hit > 90%, compression working). | Primary — only emitted post-remediation. |341| `ALREADY_OPTIMAL` | All nine dimensions at cost-optimal config AND Security Savings Bundle evaluated (whether adopted or rejected with rationale). | Primary — terminal for healthy findings. |342| `NEED_MORE_INFO` | Data gate failed for one or more dimensions: viewer geography unknown for Price Class, metrics absent for cache/origin, WAF/Shield state indeterminate. | Pre-decision — emit per-dimension; the other dimensions can still emit OPPORTUNITY_FOUND. |343344**Rule:** a partial NEED_MORE_INFO for one dimension does NOT block345OPPORTUNITY_FOUND on the other dimensions. Surface both — the346operator can apply the confirmed dimensions while collecting data347for the deferred one.348349## Cache-hit-ratio improvement targets (concrete formula)350351Target hit-ratio formula and per-content-type target table moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).352Load on demand when setting per-content-type targets or quantifying the savings from closing the gap.353354## Error handling — CLI and data-source failures355356API failure tables (CloudFront config, CloudWatch, Cost Explorer, WAF/Shield) and the aggregate retry policy moved verbatim to [references/error-handling.md](references/error-handling.md).357Load on demand when a data-source CLI call fails.358359## Anti-Patterns — NEVER do these things360361- NEVER recommend `PriceClass_100` without confirming viewer362 geography. APAC/South-America-only viewers will see significantly363 higher latency routed through US/EU edges. The 20-40% savings is364 not justified if it breaks the viewer experience for ≥ 5% of365 traffic.366367- NEVER recommend `PriceClass_100` for a live-video streaming368 workload with global viewers. Latency-sensitive streaming requires369 edge proximity; the savings from Price Class cannot offset viewer370 churn from buffering.371372- NEVER recommend enabling Origin Shield on an S3 origin with low373 request count (< 10M/month) without doing the break-even math.374 Shield's $0.0125/GB exceeds the S3 GET savings on375 low-request-volume distributions. Shield is a high-volume376 optimization.377378- NEVER recommend migrating a Lambda@Edge function to CloudFront379 Functions without measuring actual runtime. Functions have a 1ms380 wall-clock limit. A 5ms Lambda@Edge function migrates to Functions381 by truncating — the function will fail silently or error out.382383- NEVER recommend dropping Shield Advanced without confirming the384 workload is not DDoS-prone. Public-facing commerce, gaming,385 finance, and election-period government sites are DDoS targets;386 the $3,000/month is insurance against a multi-million-dollar387 outage.388389- NEVER recommend dropping WAF rules without checking CloudWatch390 metrics for the rule. A rule with 0 blocks over 30 days is unused;391 a rule with 1M blocks is actively protecting. Removing an active392 rule opens a security hole.393394- NEVER recommend a single Price Class for a multi-tenant SaaS395 workload without consulting per-tenant viewer geography. Tenant A396 may be US-only; Tenant B may be APAC-majority. Per-tenant397 distributions may be needed (multi-distribution architecture).398399- NEVER recommend changing multiple dimensions in a single deploy.400 CloudFront updates are atomic per-deploy, but isolating impact401 requires one dimension per deploy. A stacked deploy that produces402 a cache-hit drop cannot be triaged ("was it the price class, the403 cache policy, or the compression?").404405- NEVER trust `get-distribution-config`'s `LastModifiedTime` as a406 proxy for "config is current." An operator may have applied a407 no-op change yesterday that bumped LastModifiedTime without408 changing the optimization-relevant fields. Always diff against409 the actual config values.410411- NEVER assume CloudFront access logging is enabled. Many412 distributions are deployed without logging. Without logs, viewer413 geography, error breakdowns, and per-edge cache-hit rates are414 invisible. Always check `DistributionConfig.Logging.Enabled`.415416- NEVER recommend Origin Shield on a distribution where the origin417 is in a different region from viewers AND cross-region transfer418 exceeds $0.05/GB. Origin Shield adds a hop; in some419 cross-region topologies it costs more than it saves.420421- NEVER recommend Brotli compression on responses that are already422 Brotli-compressed at the origin. Double-compression is wasteful423 and can corrupt the response. Check origin response headers for424 `Content-Encoding: br` before enabling Brotli on the distribution.425426- NEVER recommend a CloudFront Security Savings Bundle commitment427 beyond the steady-state CloudFront + WAF spend. The commitment is428 a 1-year lock; committing above steady-state leaves you paying429 for unused discount.430431- NEVER recommend migrating a custom origin to S3 without verifying432 the content is genuinely static. Dynamic responses (HTML with433 per-user personalization) cannot be served from S3 without434 pre-generation. A "static" path that includes session-specific435 content will break when moved to S3.436437- NEVER assume the AWS-managed `CachingOptimized` cache policy is438 optimal for all static content. It sets TTL=31536000 (1 year);439 content that changes weekly will be stale for up to a year unless440 invalidated. Use a custom policy with shorter TTL OR add441 invalidation hooks to the deploy pipeline.442443- NEVER recommend Lambda@Edge for sub-1ms logic that could run as444 a CloudFront Function. The 40x cost differential is significant445 at high invocation counts. Always check the runtime profile446 before choosing Lambda@Edge.447448- NEVER recommend enabling compression on SSE / streaming responses.449 Compression breaks the chunk-transfer semantics and causes viewer-450 side buffering failures. Compression is for finite-size responses451 only.452453- NEVER skip the post-deploy validation step. CloudFront config454 changes are eventually-consistent; CacheHitRate and Requests455 metrics take 5-15 minutes to reflect the new config. Verify456 with `get-distribution --query 'Distribution.Status'` and457 CloudWatch before declaring the optimization complete.458459- NEVER recommend the CloudFront Security Savings Bundle without460 modeling the breakage cost. The bundle is a 1-year commit; if461 traffic drops (e.g., seasonal site), the commit is still owed.462463## Quick navigation464465| You want to... | Jump to |466|---|---|467| Decide Price Class | Step 4 — Price Class optimization |468| Diagnose low cache hit ratio | Step 5 — Cache hit ratio optimization |469| Decide S3 origin vs custom origin | Step 6 — Origin optimization |470| Decide whether to enable compression | Step 7 — Compression optimization |471| Decide whether Origin Shield is worth it | Step 8 — Origin Shield optimization |472| Decide Lambda@Edge vs CloudFront Functions | Step 9 — Edge compute optimization |473| Decide whether to keep Shield Advanced | Step 10 — Security cost optimization |474| Build the savings projection | Step 11 — Impact estimation |475| Handle missing data | Step 1 — Validate input and data sufficiency |476| Handle API errors | Error handling section |477478## Expert heuristic — the 60-second triage479480The 60-second triage (six checks on config, hit rate, CE usage types, Lambda@Edge, Shield, WAF rules) moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).481Run it before deep-diving any single dimension.482483## Pre-flight safety checks (run before any remediation CLI)484485Pre-flight safety checks (CONFIRMATION GATE, snapshot, one-dimension-per-deploy, fleet batching, invalidation cost, replica deletion) moved verbatim to [references/diagnostic-commands.md](references/diagnostic-commands.md).486Load them before emitting any remediation CLI.487488## Remediation guidance489490Per-dimension remediation CLI sequences (price class, cache policy, compression, origin, shield, edge compute, security, already-optimal) moved verbatim to [references/error-handling.md](references/error-handling.md).491Load on demand when writing the MIGRATION_STEPS block.492493## Deep reference: CloudFront pricing and limit cheat sheet494495Pricing tiers, quota reference, and the Functions-vs-Lambda@Edge capability matrix moved verbatim to [references/cloudfront-pricing-reference.md](references/cloudfront-pricing-reference.md).496Load on demand for pricing math and limit checks.497498## Recent AWS features (2024-2026)499500Recent AWS features (2024-2026) moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).501Load on demand when scoping Savings Bundle, OAC, KeyValueStore, continuous deployment, MRAP, or VPC origins.502503## References (load on demand)504505- [references/cloudfront-pricing-reference.md](references/cloudfront-pricing-reference.md) — pricing matrix, Origin Shield break-even, WAF/Shield pricing; now also the pricing cheat sheet (tiers, quotas, Functions vs Lambda@Edge) moved from SKILL.md506- [references/advanced-patterns.md](references/advanced-patterns.md) — philosophy, Step 0 gotchas, Step 1-11 deep dives (matrices, probes, worked math), hit-ratio targets, 60-second triage, recent AWS features moved from SKILL.md507- [references/diagnostic-commands.md](references/diagnostic-commands.md) — required data-source pulls and pre-flight safety checks moved from SKILL.md508- [references/error-handling.md](references/error-handling.md) — CLI/data-source failure tables, retry policy, and per-dimension remediation CLI moved from SKILL.md509- [references/worked-examples.md](references/worked-examples.md) — ALREADY_OPTIMAL and NEED_MORE_INFO worked examples moved from SKILL.md510511## Domain512513AWS CloudOps / CloudFront CDN Cost Optimization, FinOps & Edge.514515## AWS documentation516517- **Amazon CloudFront Developer Guide** — https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html518- **CloudFront pricing** — https://aws.amazon.com/cloudfront/pricing/519- **CloudFront Functions** — https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-functions.html520- **Lambda@Edge** — https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-at-the-edge.html521- **Origin Shield** — https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/origin-shield.html522- **Origin Access Control** — https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html523- **AWS WAF + CloudFront** — https://docs.aws.amazon.com/waf/latest/developerguide/cloudfront-features.html524- **AWS Shield** — https://docs.aws.amazon.com/waf/latest/developerguide/shield-chapter.html525- **CloudFront Security Savings Bundle** — https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/security-savings-bundle.html526- **AWS Well-Architected Framework — Cost Optimization** — https://docs.aws.amazon.com/wellarchitected/latest/cost-optimization-pillar/welcome.html