What makes up a CloudWatch Logs cost bill?
A CloudWatch Logs bill has a handful of line items, and they scale with different things:
| Component | Billed on | What drives it |
|---|---|---|
| Ingestion | Per GB, uncompressed, at write time | Every byte your applications and agents send |
| Archival storage | Per GB-month, after compression | Retention period × compressed volume |
| Logs Insights | Per GB scanned by queries | Query time range and how many log groups are selected |
| Vended logs | Per GB, on a separate rate schedule | AWS services that publish logs for you, such as VPC Flow Logs |
| Data transfer | Per GB moved | Subscription filters, exports, and cross-region delivery |
Ingestion usually dominates because you pay it once, at the full uncompressed size, at a per-GB rate far higher than storage. Storage is measured after compression and accrues slowly.
Illustrative estimate (assumed numbers, not a benchmark). Assume $0.50/GB ingestion, $0.03/GB-month storage, 6:1 compression, 1,000 GB ingested per month, and 30-day retention.
- Ingestion = GB ingested × ingestion rate = 1,000 × $0.50 = $500/month
- Storage = (GB retained ÷ compression ratio) × storage rate = (1,000 ÷ 6) × $0.03 ≈ $5/month
Under these assumptions, ingestion is about 99% of the combined cost. Long retention narrows the gap but rarely closes it.
Don't take this ratio on faith. In Cost Explorer, filter to CloudWatch and group by Usage Type. This splits ingestion (DataProcessing-Bytes), storage (TimedStorage-ByteHrs), and the other components into separate lines for your account. Prices vary by region and change over time, so check current rates for the regions you run in.
Why don't metric filters and subscription filters reduce ingestion cost?
Metric filters and subscription filters evaluate log events after CloudWatch Logs has accepted them. By the time a filter pattern matches or discards an event, the ingestion charge for those bytes has already been recorded. A filter that drops 90% of events before forwarding them to a subscription target saves money downstream, but your ingestion line stays the same.
Here is the order in which each control acts:
- Source log level. The application decides what to emit. This cuts ingestion.
- Agent or forwarder filtering. Include/exclude rules in the collector drop events before they are sent. This cuts ingestion.
- Ingestion. CloudWatch Logs bills every byte it receives.
- Metric and subscription filters. These run on ingested data and do not reduce ingestion.
- Storage. Billed on the archived, compressed size.
- Retention. Deletes stored data after a set period. This reduces storage only.
Only the first two stages reduce DataProcessing-Bytes.
Subscription filters also add costs of their own. A Lambda target bills invocations and duration. Kinesis Data Streams bills shard or on-demand throughput. Firehose bills data processed and the destination's storage. Forwarding everything and filtering at the destination means paying for the same data more than once.
This ordering also explains a common misread. Teams often shorten retention from "never expire" to 30 days and then see the bill barely move. For most high-volume log groups, ingestion is the dominant cost, and retention never touches it. The optimization did work. It was applied to the smaller part of the bill.
+-----------------------------+
| 1. Source log level | <-- cuts ingestion
+-----------------------------+
|
v
+-----------------------------+
| 2. Agent / forwarder filter | <-- cuts ingestion
+-----------------------------+
|
v
+=============================+
| 3. CloudWatch Logs ingestion| <-- billed per byte received;
| (DataProcessing-Bytes) | charge is fixed from here on
+=============================+
| |
v v
+--------------+ +----------------------+ +----------------------+
| 5. Storage | | 4. Metric and |--->| Lambda / Kinesis / |
| (compressed) | | subscription filters | | Firehose target |
+--------------+ | no ingestion savings | | adds downstream cost |
| +----------------------+ +----------------------+
v
+--------------+
| 6. Retention | <-- cuts storage only, not ingestion
+--------------+
Only the source log level and agent filtering act before CloudWatch Logs bills ingestion. Metric and subscription filters, storage and retention all act after that charge, and subscription targets add their own downstream costs.
How do you find which log groups drive the most cost?
Start with two rankings, because they answer different questions. The storedBytes field returned by aws logs describe-log-groups shows what each group is costing you in storage today. The IncomingBytes metric in the AWS/Logs namespace, which has a LogGroupName dimension, shows what each group is costing you in ingestion. Sum IncomingBytes over the last 30 days per log group and sort descending. The two lists rarely match. A group with short retention can rank low on stored bytes and still top the ingestion list. Since ingestion usually dominates the bill, IncomingBytes should drive your priorities.
Expect a steep curve. In most accounts, a handful of groups account for most of the ingested volume. Those groups are where reduction work pays off.
For each top group, run a Logs Insights query that clusters similar messages and counts them. The pattern command does this, or you can group by a normalized field such as logger name or message template. The goal is to find the specific lines responsible for the volume. Typical results are a health-check log on every request, a debug statement left on in production, or a full request payload serialized into every entry.
Logs Insights bills per GB of data scanned, so an audit query can add to the cost it is investigating. Select one log group, start with a short time range such as an hour, and widen it only if the sample looks unrepresentative.
The platform team should own this audit, because it can see every account. Service owners should review their own top patterns. Run it monthly, and again after major releases, since new code paths are the most common source of new log volume.
#!/usr/bin/env bash
# Audit sketch: rank log groups by storage and by ingestion, then sample
# the noisiest message patterns in one group. Uses GNU date (Linux).
set -euo pipefail
# 1) Storage ranking: what each group costs to keep today.
aws logs describe-log-groups \
--query 'logGroups[*].[logGroupName,storedBytes]' --output text \
| sort -k2 -nr | head -20
# 2) Ingestion ranking: sum IncomingBytes over 30 days per group.
# One 30-day period (2592000 s) returns a single Sum datapoint.
START=$(date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%SZ)
END=$(date -u +%Y-%m-%dT%H:%M:%SZ)
for g in $(aws logs describe-log-groups --query 'logGroups[*].logGroupName' --output text); do
sum=$(aws cloudwatch get-metric-statistics \
--namespace AWS/Logs --metric-name IncomingBytes \
--dimensions Name=LogGroupName,Value="$g" \
--start-time "$START" --end-time "$END" \
--period 2592000 --statistics Sum \
--query 'Datapoints[0].Sum' --output text)
echo -e "${sum}\t${g}"
done | grep -v '^None' | sort -k1 -gr | head -20
# 3) Pattern sample for ONE top group over ONE hour.
# Logs Insights bills per GB scanned, so keep scope narrow.
GROUP="/aws/lambda/checkout-service" # placeholder: pick from step 2
QID=$(aws logs start-query \
--log-group-name "$GROUP" \
--start-time "$(date -u -d '1 hour ago' +%s)" --end-time "$(date -u +%s)" \
--query-string 'pattern @message | sort @sampleCount desc | limit 20' \
--query queryId --output text)
sleep 10 # queries run asynchronously; re-run get-query-results if status is Running
aws logs get-query-results --query-id "$QID"
A bash audit that ranks log groups by storedBytes and by 30-day IncomingBytes, then runs a narrowly scoped one-hour Logs Insights pattern query against a single top group to find the noisiest message patterns.
How can you reduce log volume at the source?
The cheapest log line is the one you never send. CloudWatch bills ingestion per GB when data arrives, so reductions only count if they happen before records reach the service.
Start with the application:
- Lower the production default level to INFO or WARN. DEBUG left on in production usually accounts for more volume than any other single pattern.
- Remove per-request debug and health-check logs. A load balancer probing every few seconds across dozens of tasks produces a constant stream that no one ever reads.
- Sample success-path logs. Keep perhaps 1 in 100 for high-volume 200 responses, and log every error.
- Shrink payloads. Log identifiers and sizes, not full request or response bodies. Emit a stack trace once per error, not at every layer that rethrows it.
For Lambda, the JSON log format and the separate application and system log-level settings let you filter platform and function output without changing code. Check which controls your runtime supports before you rely on them, because behavior differs between managed runtimes and custom ones.
On hosts and containers, the CloudWatch agent or Fluent Bit can drop records before they leave the machine. Treat those filter rules as code. A regex that is too broad drops records silently, and configs drift as base images change. Put them in version control, add tests that run sample lines through them, and review changes to them.
The risk is missing data during an incident. You can limit that risk in three ways: make log levels changeable at runtime so you can raise them temporarily, always log errors in full, and rely on traces and metrics for the success path.
# fluent-bit.conf: drop noisy records on the host so they are never sent to CloudWatch
[SERVICE]
Flush 5
Log_Level info
[INPUT]
Name tail
Path /var/log/app/*.log
Tag app.*
# Without a parser, each raw line is stored under the key "log"
# Drop load balancer health-check access lines
[FILTER]
Name grep
Match app.*
Exclude log GET /health
# Drop DEBUG lines in case an image ships with DEBUG enabled.
# Keep this pattern narrow. An over-broad regex drops records silently.
[FILTER]
Name grep
Match app.*
Exclude log level=debug
[OUTPUT]
Name cloudwatch_logs
Match app.*
region us-east-1
log_group_name /example/app/prod
log_stream_prefix host-
auto_create_group false
A version-controlled Fluent Bit config that uses grep filters to drop health-check and DEBUG lines before the remaining records are shipped to CloudWatch Logs.
When should you use Infrequent Access logs instead of Standard?
Infrequent Access is a log class with a lower per-GB ingestion price than Standard. AWS gives up a set of real-time features in exchange, so the price difference depends on how you use the logs, not only on how much you send.
| Aspect | Standard | Infrequent Access |
|---|---|---|
| Ingestion price | Baseline | Lower per GB |
| Metric filters | Supported | Check current comparison |
| Subscription filters | Supported | Check current comparison |
| Live tailing | Supported | Check current comparison |
| Querying stored logs | Supported | Supported |
| Change class later | Not possible | Not possible |
AWS has changed this feature set over time. Read the current log class comparison before you decide, and don't rely on what you remember or on an older design doc.
The class is set when you create the log group and cannot be changed afterward. To migrate, you create a new group in the other class and repoint every producer to it, including agents, Lambda functions, container log drivers and anything defined in infrastructure-as-code. The old group keeps its history until retention expires, so queries need to cover both groups during the transition.
Infrequent Access fits high-volume logs that you only read after the fact:
- Debug and audit trails
- Verbose application logs kept for forensics
- Batch job output
- Compliance records that someone queries a few times a year
Avoid it when anything downstream reacts to the log stream as it arrives. Examples:
- An alarm built on a metric filter
- A subscription filter that feeds a SIEM, a stream processor or a cross-account pipeline
- An on-call workflow that depends on live tailing during an incident
Moving those groups saves ingestion cost but breaks detection.
How should you set log retention and long-term archival?
Retention is the other lever, and it works differently from everything above. New log groups default to Never expire, so any group created by hand, by a framework, or implicitly by a service (Lambda creates its log group on first invocation if none exists) keeps accumulating stored data indefinitely. Retention affects storage charges only. Ingestion is billed when an event arrives, so shortening retention never reduces the ingestion line.
Enforce retention per group
Declare every log group in infrastructure as code with an explicit retention value, for example RetentionInDays in CloudFormation or retention_in_days in Terraform. Pre-create groups for functions and services so that the platform cannot auto-create one without a policy. As a backstop, run a scheduled audit that lists log groups, flags any without a retentionInDays value, and either alerts or applies a default.
The minimum retention should come from legal, security and compliance owners, not from whoever owns the bill. The cost owner can push back on durations that nobody can justify. Debugging needs usually set a much shorter window than audit needs.
Archive to object storage for multi-year needs
If you must keep logs for years, keep a short CloudWatch retention and move older data to S3. You have two options:
- Scheduled export tasks, which run in batches.
- A subscription filter to a delivery stream, which delivers in near real time.
Weigh the trade-offs before you move data:
- Extra charges: You pay delivery-stream processing, S3 requests and storage, and any cross-region transfer, on top of the ingestion you already paid.
- No Logs Insights: Archived data can't be queried with Logs Insights. You need a separate query engine over S3.
- Delay: Export tasks can take hours to complete. Plan for that lag before archived data is searchable during an investigation.
# Scheduled retention audit (run from cron or a scheduled function).
# Finds log groups still set to 'Never expire' and either reports them
# or applies a default. The default is a placeholder: take the real
# minimum from your compliance/security owners, not from the bill.
import boto3
DEFAULT_RETENTION_DAYS = 30 # must be one of the values CloudWatch accepts
APPLY_FIX = False # start in report-only mode; flip after review
logs = boto3.client("logs", region_name="us-east-1")
def groups_without_retention():
paginator = logs.get_paginator("describe_log_groups")
for page in paginator.paginate():
for group in page["logGroups"]:
# A missing retentionInDays key means the group never expires.
if "retentionInDays" not in group:
yield group["logGroupName"], group.get("storedBytes", 0)
def main():
offenders = list(groups_without_retention())
for name, stored in offenders:
print(f"NO RETENTION: {name} ({stored} bytes stored)")
if APPLY_FIX:
# Affects storage only; ingestion already billed is unchanged.
logs.put_retention_policy(
logGroupName=name,
retentionInDays=DEFAULT_RETENTION_DAYS,
)
print(f"{len(offenders)} log group(s) without a retention policy")
if __name__ == "__main__":
main()
A boto3 audit script that pages through all log groups, flags any still set to never expire, and can optionally apply a default retention policy as a backstop to infrastructure-as-code settings.
How much can ingestion cuts save? An illustrative estimate and checklist
Illustrative estimate (assumed numbers, not a benchmark)
Every input below is an assumption. Replace each one with your own region's pricing and your measured volume.
- Ingestion price: $0.50 per GB
- Storage price: $0.03 per GB-month
- Daily ingestion: 100 GB, of which 60% is debug output
- Compression on stored data: 5:1
- Before: retention set to never expire, with 12 months of history. After: debug removed and 30-day retention.
Formulas:
- Monthly ingestion = daily GB × 30 × ingestion price
- Monthly storage = daily GB × compression ratio × retained days × storage price
| Scenario | Ingestion / month | Stored GB | Storage / month |
|---|---|---|---|
| Before (100 GB/day, 365 days kept) | 3,000 GB × $0.50 = $1,500 | 20 × 365 = 7,300 | $219, growing every month |
| After (40 GB/day, 30 days kept) | 1,200 GB × $0.50 = $600 | 8 × 30 = 240 | $7.20, flat |
Ingestion dominates this bill, and only cutting daily volume reduces it. Retention acts on the smaller line, which is retained compressed bytes. Without retention, that line keeps growing every month.
Checklist
- Default retention in IaC modules. New log groups should never fall back to "never expire."
- Log class chosen at creation. Pick Standard or Infrequent Access deliberately for each log group.
- Log-level policy per environment. Production defaults to INFO or higher. DEBUG requires a time-boxed override.
- Agent filtering. Drop health checks and noisy lines before they are shipped.
- IncomingBytes anomaly alarms. A verbose deploy then gets caught within days, not on the invoice.
These defaults also save engineering time. When every log group has known retention, class, and level, a month-end spike points to a single change. Nobody has to audit hundreds of log groups to find it.
How OneEnv can help
Disclosure: OneEnv is the product behind this blog.
OneEnv (oneenv.io) is a workspace-based governance platform for the things services share — environment variables, database structure, API routes and validation rules. A change to a shared value is staged on a branch, reviewed once, and then every affected service explicitly approves or rejects it before it goes live, so you can see who a change touches before it ships instead of finding out in production.
Applied to cloudwatch logs cost, this is where it helps:
Saves time
- Every service that inherits a shared value is listed in one place, so nobody searches repos and chats to find out who is affected.
- One review per branch replaces coordinating each team separately; each service still keeps its own approve/reject.
- Changing a shared variable is one edit and one review instead of editing every service's
.envby hand.
Saves cost
- Fewer production incidents and rollbacks caused by a shared value, route or column changing under a consumer unannounced.
- Less duplicated configuration to maintain: one shared definition inherited by many services.
- A wrong or stale value is caught at review time by the services it affects, not by a failed deploy.
- OneEnv has a free plan (1 workspace, unlimited services and members, full governance), so trying it costs nothing.
These are qualitative benefits, not measured results — how much you save depends on how many services share the value.
Want to try it? Start at oneenv.io.