CloudWatch Logs Cost Optimizer
What this skill does
Translates a CloudWatch Logs footprint (log groups, retention settings,
ingestion volume, query patterns, agent configuration) into a concrete
cost-optimization recommendation with a dollar-denominated savings
estimate. The verdict reflects the highest-leverage action across six
dimensions — retention, query patterns, agent buffering, cold-storage
export, subscription filters, and vended destination placement — applied
in priority order. Always pairs the recommendation with exact CLI
commands or infrastructure-as-code snippets.
Quick navigation
| Section |
What it covers |
When to jump here |
| Quick start |
Four headline rules and the cost formula |
First read |
| Mindset |
Why retention is the #1 lever |
Understanding the approach |
| Quick reference — verdict thresholds |
Decision matrix at a glance |
Classifying a log group |
| Pre-flight data gate |
CloudWatch metrics, Cost Explorer |
Before any recommendation |
| Step 0 non-obvious behaviours |
Billing model gotchas, EMF, vended logs |
Edge cases |
| Step 1 Retention |
Never-expire sweep, tiered retention |
The headline savings dimension |
| Step 2 Logs Insights vs metric filters |
Query-to-filter migration |
Frequent-query log groups |
| Step 3 CloudWatch agent buffer tuning |
batch_count, batch_size, idle hosts |
High-volume agents |
| Step 4 Firehose S3 export for cold storage |
Compliance archive pipeline |
Long-retention compliance logs |
| Step 5 Subscription filter / cross-account |
Aggregation cost, fan-out |
Multi-account setups |
| Step 6 Vended log destinations |
VPC Flow Logs, Route53 Resolver to S3 |
High-volume vended logs |
| Step 7 Data protection policy |
PII reduction at the account level |
Compliance-driven cost cut |
| Step 8 Impact estimation |
The cost formula and worked math |
Every recommendation |
| Output format |
VERDICT block + worked examples |
Emitting the result |
| Anti-Patterns — NEVER |
Common misclassifications |
Self-check before emit |
| Pre-flight safety checks |
CONFIRM gate, retention audit |
Before any apply CLI |
Quick start
- Retention is the #1 lever. A log group with
RetentionInDays = 0
(Never expire) accumulates storage indefinitely at $0.03/GB-month.
Moving a 500 GB group from Never to 30 days saves ~$13,500/year in
storage alone. Sweep Never-expire groups FIRST — they are the largest
source of unintended CloudWatch Logs spend.
- Cost formula (memorise this):
monthly_cost = (ingested_GB × $0.50) # ingestion + (stored_GB × $0.03) # storage (retention-dependent) + (PutLogEvents_requests / 1M × $0.40) # API ingestion requests + (insights_GB_scanned × $0.005) # Logs Insights queries
- Logs Insights queries are priced by GB scanned, not by result.
A query scanning 500 GB costs $2.50 regardless of whether it returns
one row or one million. Frequent scheduled queries should become
metric filters (free) or CloudWatch Metric Queries on dashboards.
- Vended logs can bypass CloudWatch Logs entirely. VPC Flow Logs,
Route53 Resolver Logs, and WAF logs can publish directly to S3 via
Firehose, avoiding the $0.50/GB ingestion fee. For high-volume vended
logs, S3 delivery is almost always cheaper.
Mindset
Mindset framing and the four cost principles (ingestion dominant, retention multiplier, S3 cold storage, hidden query cost) moved verbatim to references/advanced-patterns.md.
Load on demand to understand why retention is the #1 lever.
Quick reference — verdict thresholds
| Observation (14-30 day window) |
Verdict |
Recommendation |
RetentionInDays = 0 (Never expire) AND StoredBytes > 50 GB |
FURTHER_OPTIMIZATION_AVAILABLE (retention) |
Step 1 — set retention to the compliance minimum (typically 30-90 days) |
RetentionInDays > 365 AND log group is not a compliance-mandated archive |
FURTHER_OPTIMIZATION_AVAILABLE (retention / cold storage) |
Step 1 or Step 4 — reduce retention or export to S3 via Firehose |
| Logs Insights queries > 100/month on a single log group AND query patterns are time-series aggregations |
FURTHER_OPTIMIZATION_AVAILABLE (query migration) |
Step 2 — convert frequent queries to metric filters |
CloudWatch agent batch_count = 1000 (default) AND PutLogEvents requests > 1M/month per host |
FURTHER_OPTIMIZATION_AVAILABLE (agent buffer) |
Step 3 — increase batch_count to 10000, tune batch_size |
| Log group retention > 180 days for compliance AND no S3 export configured |
FURTHER_OPTIMIZATION_AVAILABLE (cold storage) |
Step 4 — deliver to S3 via Firehose, reduce Logs retention to 30 days |
| VPC Flow Logs destined to CloudWatch Logs at > 50 GB/day ingestion |
FURTHER_OPTIMIZATION_AVAILABLE (vended destination) |
Step 6 — redirect to S3 via Firehose |
| Account-level data protection policy not configured AND PII-dense application logs |
FURTHER_OPTIMIZATION_AVAILABLE (data protection) |
Step 7 — enable account-level data protection to mask PII |
| All dimensions verified AND retention set to compliance minimum AND Insights queries converted AND cold storage in S3 |
OPTIMIZED |
None — continue monitoring |
IncomingBytes metrics absent or window < 14 days |
NEED_MORE_INFO |
Pull 14-30 day CloudWatch data, re-evaluate |
| All dimensions verified AND a change was applied and confirmed this session |
OPTIMIZED |
Emit post-state verification |
Pre-flight: data gate (run before any optimization decision)
Data-gate prose, the required data-source list (describe-log-groups, IncomingBytes/IncomingLogEvents, metric/subscription filters, CloudTrail StartQuery, Cost Explorer), the metrics-vs-Cost-Explorer ground-truth rule moved verbatim to references/diagnostic-commands.md; the data-quality short-circuit table moved to references/advanced-patterns.md.
Load on demand before pulling metrics for an optimization decision.
Process — Optimization logic (apply in order)
Step 0: Non-obvious behaviours that change the recommendation
Step 0 non-obvious behaviours (Never-expire semantics, retroactive retention, per-GB-scanned Insights, free metric filters, EMF tradeoff, PutLogEvents batching, Firehose crossover, vended-log destinations, subscription fan-out, data-protection masking) moved verbatim to references/advanced-patterns.md.
Load on demand — each gotcha routes the recommendation away from the obvious choice.
Step 1: Log group retention (the #1 lever)
Retention-sweep rationale moved verbatim to references/advanced-patterns.md; the never-expire jq sweep and put-retention-policy CLI moved to references/diagnostic-commands.md.
Load on demand when executing the retention sweep; the tier matrix and decision gate stay inline below.
Retention tier decision matrix:
| Log type |
Recommended retention |
Rationale |
| Application logs (debug/info) |
7-30 days |
Operational debugging window; beyond 30 days use S3 |
| Application logs (error/warn) |
30-90 days |
Incident investigation window |
| Audit / security logs |
90-365 days (then S3) |
Compliance short-term; S3 for long-term |
| Lambda function logs |
7-30 days |
Most debugging happens within 7 days of deployment |
| VPC Flow Logs |
7-30 days in Logs; archive to S3 |
Security investigations are post-hoc queries |
| API Gateway access logs |
7-30 days |
Operational debugging; use Athena on S3 for long-term |
| Container logs (ECS/EKS via Firelens) |
7-14 days |
Use a dedicated log aggregator for longer retention |
Decision gate after retention audit:
| Current retention |
StoredBytes |
Verdict |
Action |
| Never expire (0) |
> 50 GB |
FURTHER_OPTIMIZATION_AVAILABLE |
Set to compliance minimum (30-90 days) |
| Never expire (0) |
< 5 GB |
FURTHER_OPTIMIZATION_AVAILABLE (low priority) |
Set to 30 days; small absolute saving |
| 90+ days AND not compliance-mandated |
> 100 GB |
FURTHER_OPTIMIZATION_AVAILABLE |
Reduce to 30 days OR export to S3 (Step 4) |
| 7-30 days |
Any |
Retention OK |
Proceed to other dimensions |
| 365+ days AND compliance-mandated |
Any |
Proceed to Step 4 (cold storage) |
S3 export is the lever |
Step 2: Logs Insights queries vs metric filters
Step 2 rationale moved verbatim to references/advanced-patterns.md; the Logs Insights cost-estimation math moved to references/worked-examples.md; the put-metric-filter CLI moved to references/diagnostic-commands.md.
Load on demand when converting frequent queries to metric filters; the migration-candidate matrix stays inline below.
When to migrate a query to a metric filter:
| Query pattern |
Metric filter candidate? |
Action |
filter @message like /ERROR/ | stats count() by bin(1min) |
YES — count of ERROR messages per minute |
Create metric filter with pattern ERROR |
stats avg(duration) by bin(5min) where duration is a JSON field |
YES — EMF or metric filter on JSON value |
Use metric filter with JSON extraction |
sort @timestamp desc | limit 20 (latest 20 errors) |
NO — ad-hoc exploration |
Keep as Insights query; it scans minimal data with tight time window |
filter @message like /timeout/ | stats count() run hourly |
YES — scheduled aggregation |
Metric filter counting timeout occurrences |
| Complex multi-line query with joins/regex |
NO — exceeds filter syntax |
Keep as Insights; consider precomputing via EMF |
Step 3: CloudWatch agent buffer tuning
Step 3 rationale and the data-loss caveat moved verbatim to references/advanced-patterns.md; the agent configuration JSON moved to references/diagnostic-commands.md; the PutLogEvents request-saving math moved to references/worked-examples.md.
Load on demand when tuning agent buffers; the parameter table stays inline below.
| Parameter |
Default |
Recommended (high-volume) |
Effect |
batch_count |
1000 |
10000 |
10x fewer PutLogEvents requests |
batch_size |
1,048,576 (1 MB) |
1,048,576 (max) |
Already at max; do not reduce |
batch_wait_time |
5 (seconds, not in older configs) |
30-60 |
Longer wait allows larger batches |
Step 4: Firehose S3 export for cold storage (compliance archives)
Step 4 rationale and architecture moved verbatim to references/advanced-patterns.md; the 500 GB 2-year Logs-vs-Firehose-S3 cost comparison moved to references/worked-examples.md; the create-delivery-stream CLI moved to references/diagnostic-commands.md.
Load on demand when planning a compliance-archive pipeline; the cold-storage decision gate stays inline below.
Decision gate for cold storage migration:
| Retention requirement |
Current destination |
Recommendation |
| 7-30 days |
CloudWatch Logs |
Keep in CW Logs (operational queries need speed) |
| 31-90 days |
CloudWatch Logs |
Keep in CW Logs if queried weekly; otherwise dual-write to S3 |
| 91-365 days |
CloudWatch Logs |
Migrate to S3 via Firehose; reduce CW Logs retention to 30 days |
| 365+ days (compliance) |
CloudWatch Logs |
Migrate to S3 + Glacier lifecycle; CW Logs retention 0-7 days |
Step 5: Subscription filter and cross-account aggregation
Step 5 rationale and the double-ingestion anti-pattern note moved verbatim to references/advanced-patterns.md.
Load on demand for cross-account aggregation; the cost-aware pattern table stays inline below.
Cost-aware aggregation patterns:
| Pattern |
Cost |
When to use |
| CW Logs → subscription filter → Firehose → S3 (central bucket) |
Firehose + S3 only |
Cheapest cross-account archive |
| CW Logs → subscription filter → Lambda → another CW Logs group |
Double ingestion ($1.00/GB) |
Avoid for high-volume logs; use Firehose instead |
| CW Logs → subscription filter → Kinesis Data Streams |
Kinesis shard cost + ingestion |
Real-time processing pipeline |
| VPC Flow Logs → directly to S3 (no CW Logs) |
S3 only ($0.023/GB-month) |
Best for pure archival |
Step 6: Vended log destinations (VPC Flow Logs, Route53 Resolver)
Step 6 rationale and the >10 GB/day S3 guidance moved verbatim to references/advanced-patterns.md.
Load on demand when placing vended logs; the destination decision table stays inline below.
VPC Flow Logs destination decision:
| Requirement |
Destination |
Cost |
| Real-time querying via Logs Insights |
CloudWatch Logs |
$0.50/GB ingest + $0.03/GB-month storage |
| Post-hoc querying via Athena |
S3 (via Firehose or direct) |
$0.023/GB-month + Athena scan cost |
| Compliance archive only |
S3 → Glacier |
$0.012/GB-month (GIR) or $0.00099 (Deep Archive) |
Step 7: Account-level data protection policy (PII reduction)
Step 7 rationale, the cost nuance (masking saves storage, not ingestion), and when-to-enable guidance moved verbatim to references/advanced-patterns.md; the put-account-policy CLI moved to references/diagnostic-commands.md.
Load on demand when enabling PII masking.
Step 8: Impact estimation
The full impact-estimation formula block (current/projected monthly cost, monthly saving) moved verbatim to references/worked-examples.md; the memorised cost formula remains in Quick start.
Load on demand when computing ESTIMATED_SAVINGS.
Step 9: Final verdict
- Any dimension recommends a change → FURTHER_OPTIMIZATION_AVAILABLE.
- All dimensions pass AND retention at compliance minimum AND no
query waste AND cold storage in S3 where applicable → OPTIMIZED.
- Change applied and verified this session → OPTIMIZED (post-state).
- Data insufficient (IncomingBytes absent, window < 14 days) →
NEED_MORE_INFO.
Never emit FURTHER_OPTIMIZATION_AVAILABLE without first discharging
every NEED_MORE_INFO/BLOCKED gate.
Output format
The minimal output template fence moved verbatim to references/worked-examples.md; the authoritative STRICT output contract with the perfect example remains inline below.
Load on demand for the short-form template.
Full worked examples (retention sweep, query migration, Firehose cold
storage, agent buffer tuning, already-optimized, NEED_MORE_INFO) are in
references/worked-examples.md.
STRICT output contract
The rules below are hard constraints. Violating any one produces a
misclassification or an arithmetic contradiction that breaks downstream
FinOps automation. Self-check EVERY emitted block against these rules
before returning the response.
Required output structure
Every response MUST be a single block using these literal labels, in this
order. Do NOT substitute markdown headings, camelCase, or bold variants.
TARGET: <log-group-name or account-level>
VERDICT: OPTIMIZED | FURTHER_OPTIMIZATION_AVAILABLE
REASON: <1-2 sentences naming the recommendation and the supporting data>
RECOMMENDATION:
Current: <retention> days, <ingested GB>/month, <Insights queries>/month, <agent batch_count>
Proposed: <retention> days, <ingested GB>/month, <Insights queries>/month, <agent batch_count>
Dimensions changed: <retention | queries | agent | cold-storage | subscription | destination | data-protection>
Dimensions checked: <list ALL seven, each ✓ (no finding) or → (finding)>
Confidence: <HIGH/MEDIUM/LOW> — <one-line rationale>
ESTIMATED_SAVINGS:
Current monthly: $<amount> ← MUST show subtotals (ingest, storage, requests, insights)
Projected monthly: $<amount>
Monthly saving: $<amount> ← MUST equal Current − Projected, 2 decimals
Annual saving: $<amount> ← MUST equal Monthly × 12
MIGRATION_STEPS:
1. <specific action with CLI command>
2. <verification step>
CONFIRM: <confirmation prompt text>
Decision tree: cost-optimization priority
Cost Optimization — START
│
Q1: RetentionInDays = 0 (Never expire) OR field absent?
├── YES → STEP 1 (retention sweep) — 90%+ storage savings; highest leverage
└── NO → Q2
│
Q2: Logs Insights queries > 100/month on this log group?
├── YES → STEP 2 (convert to metric filters) — $0.005/GB scan → free
└── NO → Q3
│
Q3: Retention > 90 days for compliance AND no S3 export?
├── YES → STEP 4 (Firehose → S3 / Glacier) — 94% cheaper long-term
└── NO → Q4
│
Q4: CloudWatch agent batch_count at default (1000)?
├── YES → STEP 3 (increase to 10000) — 10x fewer PutLogEvents requests
└── NO → Q5
│
Q5: Subscription filters fanning out to another CW Logs group?
├── YES → STEP 5 (redirect to Firehose) — eliminates double ingestion ($1.00/GB)
└── NO → Q6
│
Q6: Vended logs (VPC Flow / Route53) to CW Logs at > 10 GB/day?
├── YES → STEP 6 (redirect to S3) — eliminates $0.50/GB ingestion
└── NO → All dimensions checked → emit OPTIMIZED
FORBIDDEN output patterns
NEVER emit VERDICT: FURTHER_OPTIMIZATION_AVAILABLE with Monthly saving: $0.00. If every dimension nets zero cost delta, the verdict
MUST be OPTIMIZED. A cost-neutral compliance improvement is surfaced
in REASON, NOT as a dollar saving.
NEVER show savings math that does not balance.
Current monthly − Projected monthly MUST equal Monthly saving,
rounded to 2 decimal places.
NEVER emit scratch lines ("WAIT — recompute", "Hmm, let me redo",
"corrected:") in the output. Finalize the math before emitting.
NEVER recommend a retention change without citing the current
RetentionInDays and StoredBytes. The REASON MUST name the data
source (describe-log-groups, Cost Explorer).
NEVER omit a dimension from the RECOMMENDATION block. The
Dimensions checked line MUST list all seven dimensions, each marked
✓ (no finding) or → (finding).
NEVER present a Firehose S3 export recommendation without including
the Firehose + S3 cost in the Projected monthly. Omitting these
inflates the apparent saving.
NEVER round intermediate formula steps differently from the final
figure. Compute at full precision, round only the displayed result.
Perfect example output — FURTHER_OPTIMIZATION_AVAILABLE with verified math
Every field below is internally consistent. Copy this shape exactly.
The scenario: a 500 GB/month application log group with Never-expire
retention has accumulated 6,000 GB over 12 months. Retention to 30
days caps storage at 500 GB steady-state (91.7% storage cost cut).
Two orphaned subscription filters waste $250/month in double ingestion.
A Firehose S3 export provides a compliance archive.
TARGET: /app/payment-service-prod
VERDICT: FURTHER_OPTIMIZATION_AVAILABLE
REASON: Application log group with Never-expire retention has accumulated
6,000 GB over 12 months at $0.03/GB-month ($180.00/month storage and
growing). Two orphaned subscription filters deliver to a decommissioned
Lambda account, adding $250.00/month in double-ingestion charges.
Retention to 30 days caps storage at 500 GB steady-state ($15.00/month,
91.7% storage reduction). A Firehose S3 export provides a compliance
archive at $26.00/month (Firehose + S3 Standard).
RECOMMENDATION:
Current: Never expire, 500 GB/month ingested, 6,000 GB stored, 0 Insights queries/month,
agent batch_count 10000, 2 subscription filters (orphaned)
Proposed: 30 days, 500 GB/month ingested, 500 GB stored (steady), 0 Insights queries/month,
agent batch_count 10000, 0 subscription filters (cleaned up),
Firehose S3 export for compliance archive
Dimensions changed: retention (Step 1) + subscription (Step 5) + cold-storage (Step 4)
Dimensions checked: retention → (Never to 30d) queries ✓ (none to convert)
agent ✓ (batch_count already 10000) cold-storage → (add Firehose S3 export)
subscription → (2 orphaned filters removed) destination ✓ (app logs, not vended)
data-protection ✓ (no PII fields detected)
Confidence: HIGH — describe-log-groups confirms RetentionInDays absent and
storedBytes=6,000 GB; describe-subscription-filters confirms 2 filters pointing
to arn:aws:lambda:us-east-1:999988887777:function:log-shipper (decommissioned).
ESTIMATED_SAVINGS:
Current monthly: $680.00
ingestion: 500 GB x $0.50 = $250.00
storage: 6,000 GB x $0.03 = $180.00
subscription double-ingestion: 500 GB x $0.50 = $250.00 (orphaned Lambda dest)
insights: 0 queries = $0.00
Projected monthly: $291.00
ingestion: 500 GB x $0.50 = $250.00 (unchanged — retention does not reduce ingestion)
storage: 500 GB x $0.03 = $15.00 (steady-state at 30-day retention)
Firehose delivery: 500 GB x $0.029 = $14.50 (compliance archive to S3)
S3 Standard storage: 500 GB x $0.023 = $11.50 (first 90 days; lifecycle to GIR after)
subscription: $0.00 (orphaned filters removed)
insights: $0.00
Monthly saving: $389.00 ($680.00 − $291.00)
Annual saving: $4,668.00
Storage-only savings: $180.00 → $15.00 = 91.7% reduction
MIGRATION_STEPS:
1. Create Firehose delivery stream to S3 for compliance archive:
aws firehose create-delivery-stream --delivery-stream-name payment-log-archive \
--s3-destination-configuration \
RoleARN=arn:aws:iam::444455556666:role/firehose-s3-role,\
BucketARN=arn:aws:s3:::payment-log-archive-bucket,\
Prefix=logs/,BufferingSize=5,BufferingInterval=300
2. Verify Firehose stream is ACTIVE before proceeding:
aws firehose describe-delivery-stream --delivery-stream-name payment-log-archive
3. Remove orphaned subscription filters (decommissioned Lambda destination):
aws logs delete-subscription-filter --log-group-name /app/payment-service-prod \
--filter-name log-shipper-lambda
aws logs delete-subscription-filter --log-group-name /app/payment-service-prod \
--filter-name log-shipper-lambda-v2
4. Set retention to 30 days (deletes logs older than 30d within hours):
aws logs put-retention-policy --log-group-name /app/payment-service-prod \
--retention-in-days 30
5. Verify retention applied + subscription filters removed:
aws logs describe-log-groups --log-group-name-prefix /app/payment-service-prod
aws logs describe-subscription-filters --log-group-name /app/payment-service-prod
CONFIRM: About to put-retention-policy on /app/payment-service-prod
(Never → 30 days). This will delete 5,500 GB of logs older than 30 days
within hours. Firehose S3 export configured for compliance archive.
Saving $389.00/month (57.2%). Storage alone: 91.7% reduction.
Proceed? (yes/no)
Self-check before emit:
Verdict semantics
| Verdict |
When to emit |
FURTHER_OPTIMIZATION_AVAILABLE |
At least one dimension has a concrete, savings-bearing recommendation. |
OPTIMIZED |
All dimensions pass (retention at compliance minimum, no query waste, cold storage in S3 where applicable). Also emitted when a change was applied and verified this session. |
NEED_MORE_INFO |
Data gate failed: metrics absent, window < 14 days, or Cost Explorer data unavailable with no CloudWatch fallback. |
BLOCKED |
Hard precondition prevents evaluation: log group in a different account without cross-account role, IAM denies logs:DescribeLogGroups. |
Zero-savings rule: If MONTHLY_SAVING == $0.00 for every dimension,
verdict MUST be OPTIMIZED, never FURTHER_OPTIMIZATION_AVAILABLE.
Exception: a compliance improvement (e.g., data protection policy) with
no cost change is surfaced in REASON, not as dollar savings.
Anti-Patterns — NEVER (top 5)
NEVER recommend a retention change without verifying compliance
requirements. Reducing retention below a regulatory minimum (e.g.,
SOX 7-year, HIPAA 6-year) can create legal liability. Always confirm
the log group is not subject to a retention mandate before recommending
a reduction.
NEVER convert a Logs Insights query to a metric filter without
verifying the query pattern is expressible in metric filter syntax.
Metric filters support a limited pattern language. Complex queries
with multiple aggregations, regex, or joins cannot be converted —
forcing them produces incorrect metrics.
NEVER reduce CloudWatch Logs retention without first confirming a
cold-storage copy exists OR the data is safe to delete. Retention
reduction is irreversible — deleted log events cannot be recovered.
For compliance logs, always configure Firehose → S3 BEFORE reducing
CW Logs retention.
NEVER increase agent batch_count without warning the operator
about the data-loss exposure on agent failure. Larger batches mean
more events in-flight at any moment. For mission-critical logs,
balance cost savings against acceptable data-loss window.
NEVER recommend redirecting VPC Flow Logs to S3 without confirming
the team's query workflow can move to Athena. Teams relying on Logs
Insights for real-time VPC Flow Log queries will lose that capability
when logs move to S3-only delivery. Surface the workflow change.
Extended anti-patterns in references/cloudwatch-logs-pricing-and-retention.md.
Pre-flight safety checks (run before any remediation CLI)
Pre-flight safety checks (CONFIRM gate, retention-deletes-data warning, metric-filter immediacy, Firehose activation wait, subscription-filter downstream consumers, masking scope, agent restart, VPC Flow non-retroactivity, 10-group batch limit) moved verbatim to references/diagnostic-commands.md.
Load on demand before executing any remediation CLI.
Recent AWS features (2024-2026)
Recent AWS features (2024-2026) moved verbatim to references/advanced-patterns.md.
Load on demand when choosing between data-protection policies, Firehose delivery, S3 Tables, or the Graviton agent.
References
references/cloudwatch-logs-pricing-and-retention.md — pricing tables,
retention tier matrix, Firehose cost math, metric filter syntax
reference, vended log destination comparison, regional pricing
multipliers, cost calculation worked examples.
references/worked-examples.md — full worked examples (retention
sweep, Insights-to-metric-filter migration, Firehose cold-storage
pipeline, agent buffer tuning, already-optimized, NEED_MORE_INFO,
end-to-end walkthrough).
References (load on demand)
- references/advanced-patterns.md — Mindset principles, Step 0 non-obvious behaviours, step rationale/nuance prose, data-quality short-circuits, and Recent AWS features (2024-2026) moved from SKILL.md
- references/diagnostic-commands.md — data-gate data sources, step CLI listings (retention sweep, metric filter, agent config, Firehose, data protection), and pre-flight safety checks moved from SKILL.md
- references/worked-examples.md — now also holds step cost math (Insights estimation, buffer savings, cold-storage comparison, impact formula) and the minimal output template moved from SKILL.md
- references/cloudwatch-logs-pricing-and-retention.md — pricing tables, retention tiers, regional multipliers (pre-existing)
Domain
AWS CloudOps / CloudWatch Logs Cost Optimization & FinOps.
AWS documentation
1---2name: cloudwatch-logs-cost-optimizer3description: 'Optimises Amazon CloudWatch Logs cost across six dimensions: log group retention (Never expire is the #1 waste — moving to 30 days typically cuts storage cost 90%+ since storage is billed at $0.03/GB-month and Never-expire groups accumulate indefinitely), Logs Insights query cost ($0.005/GB scanned — frequent queries should be converted to metric filters which are free), CloudWatch agent buffer tuning (batch_count and batch_size reduce PutLogEvents API charges at $0.40/million ingestion requests), S3 export via Firehose for cold-storage compliance archives ($0.023/GB-month S3 Standard vs Logs $0.50/GB ingestion + $0.03/GB-month storage), subscription filter cost-aware cross-account aggregation, and vended log destinations (VPC Flow Logs and Route53 Resolver Logs sent to S3 directly bypass Logs ingestion fees entirely). Evaluates account-level data protection policies for PII storage reduction, embedded metric format tradeoffs, and log group aggregation patterns. Emits OPTIMIZED when no cost lever yields f...'4license: Apache-2.05compatibility: Agent runtime that reads SKILL.md (Claude Code, Cursor, Windsurf, Codex, Gemini). Offline recommendation classification works from pasted CloudWatch Logs metrics, retention settings, and Cost Explorer findings. Live-account optimization uses aws logs describe-log-groups, aws logs describe-metric-filters, aws logs describe-subscription-filters, aws cloudwatch get-metric-statistics (IncomingBytes, IncomingLogEvents), aws firehose describe-delivery-streams, aws ce get-cost-and-usage (AWS CLI...6metadata:7 source: https://skillmd.com/skills/jhkchan/cloudwatch-logs-cost-optimizer8 domain: aws-cloudops9 complexity: medium10 requires_llm: 'true'11 phase: '3'12 supports_pipeline: 'true'13 entry_point: 'false'14 family: Management15 task_type: optimize16 skill_class: capability17 lifecycle_status: active18 verdict_shape: OPTIMIZED | FURTHER_OPTIMIZATION_AVAILABLE19 when_to_use: Optimising CloudWatch Logs cost, triaging retention sweep candidates (Never-expire groups), migrating frequent Logs Insights queries to metric filters, planning a Firehose-to-S3 cold-storage pipeline for compliance archives, tuning CloudWatch agent buffer settings to reduce PutLogEvents request charges, evaluating vended log destination placement (VPC Flow Logs to S3 vs CloudWatch Logs), or running a FinOps audit of observability spend.20 when_not_to_use: CloudWatch alarm configuration or tuning (use cloudwatch-alarm-auditor), Logs Insights query debugging or syntax help (use cloudwatch-logs-insights-troubleshooter), logs-not-ingesting investigations (use cloudwatch-logs-not-ingesting-troubleshooter), S3 storage class optimization for non-log objects (use s3-storage-class-optimizer), or Firehose delivery stream troubleshooting. This skill focuses on cost-driven optimization of CloudWatch Logs, not functional debugging of log pipelines.21 activation_triggers: optimise CloudWatch Logs cost, CloudWatch Logs retention sweep, CloudWatch Logs Never expire, CloudWatch Logs Insights cost, metric filter vs Logs Insights, CloudWatch agent batch size, CloudWatch agent buffer tuning, PutLogEvents cost, Firehose S3 export logs, cold storage compliance archive, VPC Flow Logs to S3, Route53 Resolver Logs cost, vended log destinations, CloudWatch Logs subscription filter cost, embedded metric format cost, CloudWatch data protection policy, PII log reduction, CloudWatch Logs FinOps, reduce observability bill, log group aggregation22 invocation_schema: 'Input: either (a) a log group identifier + live-account context, (b) a Cost Explorer CloudWatch Logs charge breakdown, OR (c) CloudWatch Logs metrics (IncomingBytes, IncomingLogEvents) with retention setting and at least 14 days of observation. Output: a deterministic TARGET/VERDICT/REASON/RECOMMENDATION/ ESTIMATED_SAVINGS/MIGRATION_STEPS block per log group (or account-level finding), where VERDICT is one of OPTIMIZED, FURTHER_OPTIMIZATION_AVAILABLE.'23 invocation_example: "# Minimal valid input (offline finding classification):\nLogGroupName: /aws/lambda/order-processor-prod\nRetentionInDays: 0 (Never expire)\nRegion: us-east-1\nStoredBytes: 842 GB\nMetrics (last 30 days):\n - IncomingBytes avg: 28 GB/day\n - IncomingLogEvents avg: 12,000,000/day\n - Logs Insights queries/month: 450 (scanning ~120 GB each)\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: CloudWatch Logs, log retention, cost optimization, Logs Insights, metric filter, subscription filter, Firehose, S3 export, cold storage, CloudWatch agent, batch size, PutLogEvents, VPC Flow Logs, Route53 Resolver Logs, vended log destinations, embedded metric format, data protection policy, PII, log aggregation, FinOps27 tags: cloudwatch, logs, management, cost-optimization, finops, retention, firehose, s3-export28---2930# CloudWatch Logs Cost Optimizer3132## What this skill does3334Translates a CloudWatch Logs footprint (log groups, retention settings,35ingestion volume, query patterns, agent configuration) into a concrete36cost-optimization recommendation with a dollar-denominated savings37estimate. The verdict reflects the highest-leverage action across six38dimensions — retention, query patterns, agent buffering, cold-storage39export, subscription filters, and vended destination placement — applied40in priority order. Always pairs the recommendation with exact CLI41commands or infrastructure-as-code snippets.4243## Quick navigation4445| Section | What it covers | When to jump here |46|---|---|---|47| Quick start | Four headline rules and the cost formula | First read |48| Mindset | Why retention is the #1 lever | Understanding the approach |49| Quick reference — verdict thresholds | Decision matrix at a glance | Classifying a log group |50| Pre-flight data gate | CloudWatch metrics, Cost Explorer | Before any recommendation |51| Step 0 non-obvious behaviours | Billing model gotchas, EMF, vended logs | Edge cases |52| Step 1 Retention | Never-expire sweep, tiered retention | The headline savings dimension |53| Step 2 Logs Insights vs metric filters | Query-to-filter migration | Frequent-query log groups |54| Step 3 CloudWatch agent buffer tuning | batch_count, batch_size, idle hosts | High-volume agents |55| Step 4 Firehose S3 export for cold storage | Compliance archive pipeline | Long-retention compliance logs |56| Step 5 Subscription filter / cross-account | Aggregation cost, fan-out | Multi-account setups |57| Step 6 Vended log destinations | VPC Flow Logs, Route53 Resolver to S3 | High-volume vended logs |58| Step 7 Data protection policy | PII reduction at the account level | Compliance-driven cost cut |59| Step 8 Impact estimation | The cost formula and worked math | Every recommendation |60| Output format | VERDICT block + worked examples | Emitting the result |61| Anti-Patterns — NEVER | Common misclassifications | Self-check before emit |62| Pre-flight safety checks | CONFIRM gate, retention audit | Before any apply CLI |6364## Quick start6566- **Retention is the #1 lever.** A log group with `RetentionInDays = 0`67 (Never expire) accumulates storage indefinitely at $0.03/GB-month.68 Moving a 500 GB group from Never to 30 days saves ~$13,500/year in69 storage alone. Sweep Never-expire groups FIRST — they are the largest70 source of unintended CloudWatch Logs spend.71- **Cost formula (memorise this):**72 `monthly_cost = (ingested_GB × $0.50) # ingestion73 + (stored_GB × $0.03) # storage (retention-dependent)74 + (PutLogEvents_requests / 1M × $0.40) # API ingestion requests75 + (insights_GB_scanned × $0.005) # Logs Insights queries`76- **Logs Insights queries are priced by GB scanned, not by result.**77 A query scanning 500 GB costs $2.50 regardless of whether it returns78 one row or one million. Frequent scheduled queries should become79 metric filters (free) or CloudWatch Metric Queries on dashboards.80- **Vended logs can bypass CloudWatch Logs entirely.** VPC Flow Logs,81 Route53 Resolver Logs, and WAF logs can publish directly to S3 via82 Firehose, avoiding the $0.50/GB ingestion fee. For high-volume vended83 logs, S3 delivery is almost always cheaper.8485## Mindset8687Mindset framing and the four cost principles (ingestion dominant, retention multiplier, S3 cold storage, hidden query cost) moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).88Load on demand to understand why retention is the #1 lever.8990## Quick reference — verdict thresholds9192| Observation (14-30 day window) | Verdict | Recommendation |93|---|---|---|94| `RetentionInDays = 0` (Never expire) AND `StoredBytes` > 50 GB | **FURTHER_OPTIMIZATION_AVAILABLE** (retention) | Step 1 — set retention to the compliance minimum (typically 30-90 days) |95| `RetentionInDays` > 365 AND log group is not a compliance-mandated archive | **FURTHER_OPTIMIZATION_AVAILABLE** (retention / cold storage) | Step 1 or Step 4 — reduce retention or export to S3 via Firehose |96| Logs Insights queries > 100/month on a single log group AND query patterns are time-series aggregations | **FURTHER_OPTIMIZATION_AVAILABLE** (query migration) | Step 2 — convert frequent queries to metric filters |97| CloudWatch agent `batch_count` = 1000 (default) AND `PutLogEvents` requests > 1M/month per host | **FURTHER_OPTIMIZATION_AVAILABLE** (agent buffer) | Step 3 — increase batch_count to 10000, tune batch_size |98| Log group retention > 180 days for compliance AND no S3 export configured | **FURTHER_OPTIMIZATION_AVAILABLE** (cold storage) | Step 4 — deliver to S3 via Firehose, reduce Logs retention to 30 days |99| VPC Flow Logs destined to CloudWatch Logs at > 50 GB/day ingestion | **FURTHER_OPTIMIZATION_AVAILABLE** (vended destination) | Step 6 — redirect to S3 via Firehose |100| Account-level data protection policy not configured AND PII-dense application logs | **FURTHER_OPTIMIZATION_AVAILABLE** (data protection) | Step 7 — enable account-level data protection to mask PII |101| All dimensions verified AND retention set to compliance minimum AND Insights queries converted AND cold storage in S3 | **OPTIMIZED** | None — continue monitoring |102| `IncomingBytes` metrics absent or window < 14 days | **NEED_MORE_INFO** | Pull 14-30 day CloudWatch data, re-evaluate |103| All dimensions verified AND a change was applied and confirmed this session | **OPTIMIZED** | Emit post-state verification |104105## Pre-flight: data gate (run before any optimization decision)106107Data-gate prose, the required data-source list (describe-log-groups, IncomingBytes/IncomingLogEvents, metric/subscription filters, CloudTrail StartQuery, Cost Explorer), the metrics-vs-Cost-Explorer ground-truth rule moved verbatim to [references/diagnostic-commands.md](references/diagnostic-commands.md); the data-quality short-circuit table moved to [references/advanced-patterns.md](references/advanced-patterns.md).108Load on demand before pulling metrics for an optimization decision.109110## Process — Optimization logic (apply in order)111112### Step 0: Non-obvious behaviours that change the recommendation113114Step 0 non-obvious behaviours (Never-expire semantics, retroactive retention, per-GB-scanned Insights, free metric filters, EMF tradeoff, PutLogEvents batching, Firehose crossover, vended-log destinations, subscription fan-out, data-protection masking) moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).115Load on demand — each gotcha routes the recommendation away from the obvious choice.116117### Step 1: Log group retention (the #1 lever)118119Retention-sweep rationale moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md); the never-expire jq sweep and put-retention-policy CLI moved to [references/diagnostic-commands.md](references/diagnostic-commands.md).120Load on demand when executing the retention sweep; the tier matrix and decision gate stay inline below.121122**Retention tier decision matrix:**123124| Log type | Recommended retention | Rationale |125|---|---|---|126| Application logs (debug/info) | 7-30 days | Operational debugging window; beyond 30 days use S3 |127| Application logs (error/warn) | 30-90 days | Incident investigation window |128| Audit / security logs | 90-365 days (then S3) | Compliance short-term; S3 for long-term |129| Lambda function logs | 7-30 days | Most debugging happens within 7 days of deployment |130| VPC Flow Logs | 7-30 days in Logs; archive to S3 | Security investigations are post-hoc queries |131| API Gateway access logs | 7-30 days | Operational debugging; use Athena on S3 for long-term |132| Container logs (ECS/EKS via Firelens) | 7-14 days | Use a dedicated log aggregator for longer retention |133134**Decision gate after retention audit:**135136| Current retention | StoredBytes | Verdict | Action |137|---|---|---|---|138| Never expire (0) | > 50 GB | **FURTHER_OPTIMIZATION_AVAILABLE** | Set to compliance minimum (30-90 days) |139| Never expire (0) | < 5 GB | **FURTHER_OPTIMIZATION_AVAILABLE** (low priority) | Set to 30 days; small absolute saving |140| 90+ days AND not compliance-mandated | > 100 GB | **FURTHER_OPTIMIZATION_AVAILABLE** | Reduce to 30 days OR export to S3 (Step 4) |141| 7-30 days | Any | Retention OK | Proceed to other dimensions |142| 365+ days AND compliance-mandated | Any | Proceed to Step 4 (cold storage) | S3 export is the lever |143144### Step 2: Logs Insights queries vs metric filters145146Step 2 rationale moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md); the Logs Insights cost-estimation math moved to [references/worked-examples.md](references/worked-examples.md); the put-metric-filter CLI moved to [references/diagnostic-commands.md](references/diagnostic-commands.md).147Load on demand when converting frequent queries to metric filters; the migration-candidate matrix stays inline below.148149**When to migrate a query to a metric filter:**150151| Query pattern | Metric filter candidate? | Action |152|---|---|---|153| `filter @message like /ERROR/ \| stats count() by bin(1min)` | YES — count of ERROR messages per minute | Create metric filter with pattern `ERROR` |154| `stats avg(duration) by bin(5min)` where duration is a JSON field | YES — EMF or metric filter on JSON value | Use metric filter with JSON extraction |155| `sort @timestamp desc \| limit 20` (latest 20 errors) | NO — ad-hoc exploration | Keep as Insights query; it scans minimal data with tight time window |156| `filter @message like /timeout/ \| stats count()` run hourly | YES — scheduled aggregation | Metric filter counting timeout occurrences |157| Complex multi-line query with joins/regex | NO — exceeds filter syntax | Keep as Insights; consider precomputing via EMF |158159### Step 3: CloudWatch agent buffer tuning160161Step 3 rationale and the data-loss caveat moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md); the agent configuration JSON moved to [references/diagnostic-commands.md](references/diagnostic-commands.md); the PutLogEvents request-saving math moved to [references/worked-examples.md](references/worked-examples.md).162Load on demand when tuning agent buffers; the parameter table stays inline below.163164| Parameter | Default | Recommended (high-volume) | Effect |165|---|---|---|---|166| `batch_count` | 1000 | 10000 | 10x fewer PutLogEvents requests |167| `batch_size` | 1,048,576 (1 MB) | 1,048,576 (max) | Already at max; do not reduce |168| `batch_wait_time` | 5 (seconds, not in older configs) | 30-60 | Longer wait allows larger batches |169170### Step 4: Firehose S3 export for cold storage (compliance archives)171172Step 4 rationale and architecture moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md); the 500 GB 2-year Logs-vs-Firehose-S3 cost comparison moved to [references/worked-examples.md](references/worked-examples.md); the create-delivery-stream CLI moved to [references/diagnostic-commands.md](references/diagnostic-commands.md).173Load on demand when planning a compliance-archive pipeline; the cold-storage decision gate stays inline below.174175**Decision gate for cold storage migration:**176177| Retention requirement | Current destination | Recommendation |178|---|---|---|179| 7-30 days | CloudWatch Logs | Keep in CW Logs (operational queries need speed) |180| 31-90 days | CloudWatch Logs | Keep in CW Logs if queried weekly; otherwise dual-write to S3 |181| 91-365 days | CloudWatch Logs | **Migrate to S3 via Firehose; reduce CW Logs retention to 30 days** |182| 365+ days (compliance) | CloudWatch Logs | **Migrate to S3 + Glacier lifecycle; CW Logs retention 0-7 days** |183184### Step 5: Subscription filter and cross-account aggregation185186Step 5 rationale and the double-ingestion anti-pattern note moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).187Load on demand for cross-account aggregation; the cost-aware pattern table stays inline below.188189**Cost-aware aggregation patterns:**190191| Pattern | Cost | When to use |192|---|---|---|193| CW Logs → subscription filter → Firehose → S3 (central bucket) | Firehose + S3 only | Cheapest cross-account archive |194| CW Logs → subscription filter → Lambda → another CW Logs group | Double ingestion ($1.00/GB) | Avoid for high-volume logs; use Firehose instead |195| CW Logs → subscription filter → Kinesis Data Streams | Kinesis shard cost + ingestion | Real-time processing pipeline |196| VPC Flow Logs → directly to S3 (no CW Logs) | S3 only ($0.023/GB-month) | Best for pure archival |197198### Step 6: Vended log destinations (VPC Flow Logs, Route53 Resolver)199200Step 6 rationale and the >10 GB/day S3 guidance moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).201Load on demand when placing vended logs; the destination decision table stays inline below.202203**VPC Flow Logs destination decision:**204205| Requirement | Destination | Cost |206|---|---|---|207| Real-time querying via Logs Insights | CloudWatch Logs | $0.50/GB ingest + $0.03/GB-month storage |208| Post-hoc querying via Athena | S3 (via Firehose or direct) | $0.023/GB-month + Athena scan cost |209| Compliance archive only | S3 → Glacier | $0.012/GB-month (GIR) or $0.00099 (Deep Archive) |210211### Step 7: Account-level data protection policy (PII reduction)212213Step 7 rationale, the cost nuance (masking saves storage, not ingestion), and when-to-enable guidance moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md); the put-account-policy CLI moved to [references/diagnostic-commands.md](references/diagnostic-commands.md).214Load on demand when enabling PII masking.215216### Step 8: Impact estimation217218The full impact-estimation formula block (current/projected monthly cost, monthly saving) moved verbatim to [references/worked-examples.md](references/worked-examples.md); the memorised cost formula remains in Quick start.219Load on demand when computing ESTIMATED_SAVINGS.220221### Step 9: Final verdict222223- Any dimension recommends a change → **FURTHER_OPTIMIZATION_AVAILABLE**.224- All dimensions pass AND retention at compliance minimum AND no225 query waste AND cold storage in S3 where applicable → **OPTIMIZED**.226- Change applied and verified this session → **OPTIMIZED** (post-state).227- Data insufficient (IncomingBytes absent, window < 14 days) →228 **NEED_MORE_INFO**.229230Never emit `FURTHER_OPTIMIZATION_AVAILABLE` without first discharging231every `NEED_MORE_INFO`/`BLOCKED` gate.232233## Output format234235The minimal output template fence moved verbatim to [references/worked-examples.md](references/worked-examples.md); the authoritative STRICT output contract with the perfect example remains inline below.236Load on demand for the short-form template.237238Full worked examples (retention sweep, query migration, Firehose cold239storage, agent buffer tuning, already-optimized, NEED_MORE_INFO) are in240`references/worked-examples.md`.241242## STRICT output contract243244The rules below are hard constraints. Violating any one produces a245misclassification or an arithmetic contradiction that breaks downstream246FinOps automation. Self-check EVERY emitted block against these rules247before returning the response.248249### Required output structure250251Every response MUST be a single block using these literal labels, in this252order. Do NOT substitute markdown headings, camelCase, or bold variants.253254```text255TARGET: <log-group-name or account-level>256VERDICT: OPTIMIZED | FURTHER_OPTIMIZATION_AVAILABLE257REASON: <1-2 sentences naming the recommendation and the supporting data>258RECOMMENDATION:259 Current: <retention> days, <ingested GB>/month, <Insights queries>/month, <agent batch_count>260 Proposed: <retention> days, <ingested GB>/month, <Insights queries>/month, <agent batch_count>261 Dimensions changed: <retention | queries | agent | cold-storage | subscription | destination | data-protection>262 Dimensions checked: <list ALL seven, each ✓ (no finding) or → (finding)>263 Confidence: <HIGH/MEDIUM/LOW> — <one-line rationale>264ESTIMATED_SAVINGS:265 Current monthly: $<amount> ← MUST show subtotals (ingest, storage, requests, insights)266 Projected monthly: $<amount>267 Monthly saving: $<amount> ← MUST equal Current − Projected, 2 decimals268 Annual saving: $<amount> ← MUST equal Monthly × 12269MIGRATION_STEPS:270 1. <specific action with CLI command>271 2. <verification step>272CONFIRM: <confirmation prompt text>273```274275### Decision tree: cost-optimization priority276277```text278Cost Optimization — START279 │280 Q1: RetentionInDays = 0 (Never expire) OR field absent?281 ├── YES → STEP 1 (retention sweep) — 90%+ storage savings; highest leverage282 └── NO → Q2283 │284 Q2: Logs Insights queries > 100/month on this log group?285 ├── YES → STEP 2 (convert to metric filters) — $0.005/GB scan → free286 └── NO → Q3287 │288 Q3: Retention > 90 days for compliance AND no S3 export?289 ├── YES → STEP 4 (Firehose → S3 / Glacier) — 94% cheaper long-term290 └── NO → Q4291 │292 Q4: CloudWatch agent batch_count at default (1000)?293 ├── YES → STEP 3 (increase to 10000) — 10x fewer PutLogEvents requests294 └── NO → Q5295 │296 Q5: Subscription filters fanning out to another CW Logs group?297 ├── YES → STEP 5 (redirect to Firehose) — eliminates double ingestion ($1.00/GB)298 └── NO → Q6299 │300 Q6: Vended logs (VPC Flow / Route53) to CW Logs at > 10 GB/day?301 ├── YES → STEP 6 (redirect to S3) — eliminates $0.50/GB ingestion302 └── NO → All dimensions checked → emit OPTIMIZED303```304305### FORBIDDEN output patterns3063071. **NEVER emit `VERDICT: FURTHER_OPTIMIZATION_AVAILABLE` with `Monthly308 saving: $0.00`.** If every dimension nets zero cost delta, the verdict309 MUST be `OPTIMIZED`. A cost-neutral compliance improvement is surfaced310 in REASON, NOT as a dollar saving.3113122. **NEVER show savings math that does not balance.**313 `Current monthly − Projected monthly` MUST equal `Monthly saving`,314 rounded to 2 decimal places.3153163. **NEVER emit scratch lines** ("WAIT — recompute", "Hmm, let me redo",317 "corrected:") in the output. Finalize the math before emitting.3183194. **NEVER recommend a retention change without citing the current320 `RetentionInDays` and `StoredBytes`.** The REASON MUST name the data321 source (describe-log-groups, Cost Explorer).3223235. **NEVER omit a dimension from the RECOMMENDATION block.** The324 `Dimensions checked` line MUST list all seven dimensions, each marked325 ✓ (no finding) or → (finding).3263276. **NEVER present a Firehose S3 export recommendation without including328 the Firehose + S3 cost in the Projected monthly.** Omitting these329 inflates the apparent saving.3303317. **NEVER round intermediate formula steps differently from the final332 figure.** Compute at full precision, round only the displayed result.333334### Perfect example output — FURTHER_OPTIMIZATION_AVAILABLE with verified math335336Every field below is internally consistent. Copy this shape exactly.337The scenario: a 500 GB/month application log group with Never-expire338retention has accumulated 6,000 GB over 12 months. Retention to 30339days caps storage at 500 GB steady-state (91.7% storage cost cut).340Two orphaned subscription filters waste $250/month in double ingestion.341A Firehose S3 export provides a compliance archive.342343```text344TARGET: /app/payment-service-prod345VERDICT: FURTHER_OPTIMIZATION_AVAILABLE346REASON: Application log group with Never-expire retention has accumulated347 6,000 GB over 12 months at $0.03/GB-month ($180.00/month storage and348 growing). Two orphaned subscription filters deliver to a decommissioned349 Lambda account, adding $250.00/month in double-ingestion charges.350 Retention to 30 days caps storage at 500 GB steady-state ($15.00/month,351 91.7% storage reduction). A Firehose S3 export provides a compliance352 archive at $26.00/month (Firehose + S3 Standard).353RECOMMENDATION:354 Current: Never expire, 500 GB/month ingested, 6,000 GB stored, 0 Insights queries/month,355 agent batch_count 10000, 2 subscription filters (orphaned)356 Proposed: 30 days, 500 GB/month ingested, 500 GB stored (steady), 0 Insights queries/month,357 agent batch_count 10000, 0 subscription filters (cleaned up),358 Firehose S3 export for compliance archive359 Dimensions changed: retention (Step 1) + subscription (Step 5) + cold-storage (Step 4)360 Dimensions checked: retention → (Never to 30d) queries ✓ (none to convert)361 agent ✓ (batch_count already 10000) cold-storage → (add Firehose S3 export)362 subscription → (2 orphaned filters removed) destination ✓ (app logs, not vended)363 data-protection ✓ (no PII fields detected)364 Confidence: HIGH — describe-log-groups confirms RetentionInDays absent and365 storedBytes=6,000 GB; describe-subscription-filters confirms 2 filters pointing366 to arn:aws:lambda:us-east-1:999988887777:function:log-shipper (decommissioned).367ESTIMATED_SAVINGS:368 Current monthly: $680.00369 ingestion: 500 GB x $0.50 = $250.00370 storage: 6,000 GB x $0.03 = $180.00371 subscription double-ingestion: 500 GB x $0.50 = $250.00 (orphaned Lambda dest)372 insights: 0 queries = $0.00373 Projected monthly: $291.00374 ingestion: 500 GB x $0.50 = $250.00 (unchanged — retention does not reduce ingestion)375 storage: 500 GB x $0.03 = $15.00 (steady-state at 30-day retention)376 Firehose delivery: 500 GB x $0.029 = $14.50 (compliance archive to S3)377 S3 Standard storage: 500 GB x $0.023 = $11.50 (first 90 days; lifecycle to GIR after)378 subscription: $0.00 (orphaned filters removed)379 insights: $0.00380 Monthly saving: $389.00 ($680.00 − $291.00)381 Annual saving: $4,668.00382 Storage-only savings: $180.00 → $15.00 = 91.7% reduction383MIGRATION_STEPS:384 1. Create Firehose delivery stream to S3 for compliance archive:385 aws firehose create-delivery-stream --delivery-stream-name payment-log-archive \386 --s3-destination-configuration \387 RoleARN=arn:aws:iam::444455556666:role/firehose-s3-role,\388 BucketARN=arn:aws:s3:::payment-log-archive-bucket,\389 Prefix=logs/,BufferingSize=5,BufferingInterval=300390 2. Verify Firehose stream is ACTIVE before proceeding:391 aws firehose describe-delivery-stream --delivery-stream-name payment-log-archive392 3. Remove orphaned subscription filters (decommissioned Lambda destination):393 aws logs delete-subscription-filter --log-group-name /app/payment-service-prod \394 --filter-name log-shipper-lambda395 aws logs delete-subscription-filter --log-group-name /app/payment-service-prod \396 --filter-name log-shipper-lambda-v2397 4. Set retention to 30 days (deletes logs older than 30d within hours):398 aws logs put-retention-policy --log-group-name /app/payment-service-prod \399 --retention-in-days 30400 5. Verify retention applied + subscription filters removed:401 aws logs describe-log-groups --log-group-name-prefix /app/payment-service-prod402 aws logs describe-subscription-filters --log-group-name /app/payment-service-prod403CONFIRM: About to put-retention-policy on /app/payment-service-prod404 (Never → 30 days). This will delete 5,500 GB of logs older than 30 days405 within hours. Firehose S3 export configured for compliance archive.406 Saving $389.00/month (57.2%). Storage alone: 91.7% reduction.407 Proceed? (yes/no)408```409410**Self-check before emit:**411- [ ] `Current monthly − Projected monthly == Monthly saving` (2 decimals)?412- [ ] `Monthly saving × 12 == Annual saving`?413- [ ] All seven dimensions listed in `Dimensions checked`?414- [ ] Every `→` dimension has a corresponding MIGRATION_STEPS entry?415- [ ] No scratch/recompute text in the block?416417## Verdict semantics418419| Verdict | When to emit |420|---|---|421| `FURTHER_OPTIMIZATION_AVAILABLE` | At least one dimension has a concrete, savings-bearing recommendation. |422| `OPTIMIZED` | All dimensions pass (retention at compliance minimum, no query waste, cold storage in S3 where applicable). Also emitted when a change was applied and verified this session. |423| `NEED_MORE_INFO` | Data gate failed: metrics absent, window < 14 days, or Cost Explorer data unavailable with no CloudWatch fallback. |424| `BLOCKED` | Hard precondition prevents evaluation: log group in a different account without cross-account role, IAM denies logs:DescribeLogGroups. |425426**Zero-savings rule:** If MONTHLY_SAVING == $0.00 for every dimension,427verdict MUST be `OPTIMIZED`, never `FURTHER_OPTIMIZATION_AVAILABLE`.428Exception: a compliance improvement (e.g., data protection policy) with429no cost change is surfaced in REASON, not as dollar savings.430431## Anti-Patterns — NEVER (top 5)4324331. **NEVER recommend a retention change without verifying compliance434 requirements.** Reducing retention below a regulatory minimum (e.g.,435 SOX 7-year, HIPAA 6-year) can create legal liability. Always confirm436 the log group is not subject to a retention mandate before recommending437 a reduction.4384392. **NEVER convert a Logs Insights query to a metric filter without440 verifying the query pattern is expressible in metric filter syntax.**441 Metric filters support a limited pattern language. Complex queries442 with multiple aggregations, regex, or joins cannot be converted —443 forcing them produces incorrect metrics.4444453. **NEVER reduce CloudWatch Logs retention without first confirming a446 cold-storage copy exists OR the data is safe to delete.** Retention447 reduction is irreversible — deleted log events cannot be recovered.448 For compliance logs, always configure Firehose → S3 BEFORE reducing449 CW Logs retention.4504514. **NEVER increase agent `batch_count` without warning the operator452 about the data-loss exposure on agent failure.** Larger batches mean453 more events in-flight at any moment. For mission-critical logs,454 balance cost savings against acceptable data-loss window.4554565. **NEVER recommend redirecting VPC Flow Logs to S3 without confirming457 the team's query workflow can move to Athena.** Teams relying on Logs458 Insights for real-time VPC Flow Log queries will lose that capability459 when logs move to S3-only delivery. Surface the workflow change.460461Extended anti-patterns in `references/cloudwatch-logs-pricing-and-retention.md`.462463## Pre-flight safety checks (run before any remediation CLI)464465Pre-flight safety checks (CONFIRM gate, retention-deletes-data warning, metric-filter immediacy, Firehose activation wait, subscription-filter downstream consumers, masking scope, agent restart, VPC Flow non-retroactivity, 10-group batch limit) moved verbatim to [references/diagnostic-commands.md](references/diagnostic-commands.md).466Load on demand before executing any remediation CLI.467468## Recent AWS features (2024-2026)469470Recent AWS features (2024-2026) moved verbatim to [references/advanced-patterns.md](references/advanced-patterns.md).471Load on demand when choosing between data-protection policies, Firehose delivery, S3 Tables, or the Graviton agent.472473## References474475- `references/cloudwatch-logs-pricing-and-retention.md` — pricing tables,476 retention tier matrix, Firehose cost math, metric filter syntax477 reference, vended log destination comparison, regional pricing478 multipliers, cost calculation worked examples.479- `references/worked-examples.md` — full worked examples (retention480 sweep, Insights-to-metric-filter migration, Firehose cold-storage481 pipeline, agent buffer tuning, already-optimized, NEED_MORE_INFO,482 end-to-end walkthrough).483484## References (load on demand)485486- [references/advanced-patterns.md](references/advanced-patterns.md) — Mindset principles, Step 0 non-obvious behaviours, step rationale/nuance prose, data-quality short-circuits, and Recent AWS features (2024-2026) moved from SKILL.md487- [references/diagnostic-commands.md](references/diagnostic-commands.md) — data-gate data sources, step CLI listings (retention sweep, metric filter, agent config, Firehose, data protection), and pre-flight safety checks moved from SKILL.md488- [references/worked-examples.md](references/worked-examples.md) — now also holds step cost math (Insights estimation, buffer savings, cold-storage comparison, impact formula) and the minimal output template moved from SKILL.md489- [references/cloudwatch-logs-pricing-and-retention.md](references/cloudwatch-logs-pricing-and-retention.md) — pricing tables, retention tiers, regional multipliers (pre-existing)490491## Domain492493AWS CloudOps / CloudWatch Logs Cost Optimization & FinOps.494495## AWS documentation496497- **Amazon CloudWatch Logs User Guide** — https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html498- **CloudWatch Logs pricing** — https://aws.amazon.com/cloudwatch/pricing/499- **CloudWatch Logs retention** — https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Working-with-log-groups-and-streams.html#SettingLogRetention500- **CloudWatch Logs Insights** — https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html501- **CloudWatch Logs metric filters** — https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/MonitoringLogData.html502- **CloudWatch Logs subscription filters** — https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Subscriptions.html503- **CloudWatch agent configuration** — https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html504- **Kinesis Data Firehose** — https://docs.aws.amazon.com/firehose/latest/dev/what-is-this-service.html505- **VPC Flow Logs** — https://docs.aws.amazon.com/vpc/latest/flow-logs/flow-logs-cwl.html506- **CloudWatch Logs data protection** — https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/data-protection.html507- **AWS CLI Logs reference** — https://docs.aws.amazon.com/cli/latest/reference/logs/508- **Well-Architected Cost Optimization** — https://docs.aws.amazon.com/wellarchitected/latest/cost-optimization-pillar/welcome.html