What makes up the CloudWatch Logs cost on your bill?

Most CloudWatch Logs bills come from three meters. Each one charges for something different, so it helps to know which part of your logging pipeline drives each.

Ingestion: charged per GB ingested

Every byte that an application, agent, Lambda function or AWS service writes to a log group is metered at ingestion time. That includes debug lines nobody reads, health-check noise and duplicate stack traces. The charge applies once, when data arrives, and you pay it even if you delete the log group an hour later. The Standard and Infrequent Access log classes have different ingestion rates. The Infrequent Access section below covers that tradeoff.

Storage: charged per GB-month of archived data

After ingestion, CloudWatch stores the data compressed and bills it per GB-month for as long as the retention setting keeps it. Text logs usually compress well, so the stored footprint is smaller than the ingested volume. The default retention never expires, so this cost grows quietly over time.

Logs Insights: charged per GB scanned

Queries are billed by how much data they scan, not by how many results they return. A broad query over a wide time range on a busy log group costs the same whether it matches one line or a million.

Why ingestion usually dominates

Ingestion bills raw, uncompressed volume at a higher per-GB rate. Storage bills a compressed footprint that you can cap with retention. The cheapest byte is one you never send, which is why this article focuses on log ingestion first.

Rates differ by region and change over time. Check the current CloudWatch pricing page for your regions rather than relying on any figures here.

+-------------+  +-------------+  +-------------+  +-------------+
| Application |  |    Agent    |  |   Lambda    |  | AWS service |
+------+------+  +------+------+  +------+------+  +------+------+
       |                |                |                |
       +----------------+-------+--------+----------------+
                                |  raw, uncompressed bytes written
                                v
              +------------------------------------+
              | [1] INGESTION: per GB ingested     |
              |     every byte, once, on arrival   |
              |     Standard vs IA class rates     |
              +-----------------+------------------+
                                |
                                v
              +------------------------------------+
              | Log group (retention setting)      |
              | default retention: never expire    |
              +-----------------+------------------+
                                |
                +---------------+----------------+
                |                                |
                v                                v
 +----------------------------+   +----------------------------+
 | [2] STORAGE                |   | [3] LOGS INSIGHTS          |
 | per GB-month, compressed   |   | per GB scanned by a query  |
 | capped by retention        |   | not per result returned    |
 +----------------------------+   +----------------------------+

Log data from every source is billed once at ingestion on its raw volume, then billed as compressed storage for as long as retention keeps it, and billed again by the GB each Logs Insights query scans.

How does CloudWatch Logs cost control work?

Every log event follows the same path, and each stage has its own control.

  1. A producer writes events to a log group. The size of each event is set entirely by the producer: the application's log level, its formatter, and any sampling it does. CloudWatch meters whatever arrives. The control here is in your code and agent configuration, and it is the only one that reduces the bytes ingested.
  2. The log group's class sets the ingestion rate. Each log group is created as either Standard or Infrequent Access. The class determines the per-GB ingestion price and which features are available on that group. It is fixed at creation, so the decision is made once per group.
  3. The retention policy sets how long stored data lives. CloudWatch keeps the compressed data until it is older than the group's retention setting and then deletes it automatically. With Never Expire, nothing is ever deleted and the storage charge keeps growing.
  4. Queries scan stored data on demand. Logs Insights reads the log groups and time range you select and bills for the bytes it scans. The controls are query scope and how often queries run, especially from dashboards.

Cost work therefore comes down to four levers, in order of usual impact: send fewer bytes, pay a lower rate on the bytes that must be sent, stop storing bytes past their useful life, and scan fewer bytes per question. The rest of this article works through each one, starting with how to measure which log groups matter.

Who should use these techniques?

The work below pays off for teams where CloudWatch Logs is a noticeable line on the AWS bill, or is growing faster than traffic. Typical cases:

  • Platform and infrastructure engineers who own shared logging configuration, agents or IaC modules. A default changed once in a shared module applies to every service that uses it.
  • Teams running many Lambda functions or containers. Each function or task gets its own log group, often auto-created with Never Expire, and verbose defaults multiply across all of them.
  • Accounts that have existed for years without a retention review. These are the cases where storage, not ingestion, has grown large enough to matter.
  • Teams sending VPC Flow Logs, load balancer logs or API access logs to CloudWatch Logs. These are high-volume by nature and often the largest groups in an account.
  • Engineers who own cost or FinOps reporting and need to explain where the logging spend comes from, not only how large it is.

If your logging spend is small relative to the rest of the account, the ranking step in the next sections will show that quickly. Setting retention on new log groups is still worth doing, because it costs little effort and stops future growth. The deeper changes, such as sampling, payload trimming and log class migration, are only worth the engineering time where the bytes are.

Why doesn't log retention alone fix the bill? An illustrative estimate

Illustrative estimate (assumed numbers, not a benchmark)

Assume 10 services each emit 5 GB/day, for 50 GB/day in total. Use placeholder prices of $0.50 per GB ingested and $0.03 per GB-month stored. These are not current AWS rates. Also assume stored logs compress 5:1.

  • Monthly ingestion = GB/day × 30 × ingestion price
  • Steady-state storage = GB/day × retention days ÷ compression ratio × storage price
  • Never Expire storage = GB/day × days retained so far ÷ compression ratio × storage price
Scenario Stored volume Storage cost/month Ingestion cost/month
30-day retention 50 × 30 ÷ 5 = 300 GB $9 $750
Never Expire, month 12 50 × 360 ÷ 5 = 3,600 GB $108 $750
Never Expire, month 36 50 × 1,080 ÷ 5 = 10,800 GB $324 $750

Under these assumptions, ingestion dominates. You pay it on every byte when the byte arrives, and retention has no effect on it. Storage is small because it is billed on the compressed size.

This produces a common trap. A team sets 30-day retention across every log group and expects a large drop. The bill moves by a few percent, and the team concludes that log cost work is futile. Retention was the right change, but it was aimed at the smaller line item. The one exception is a log group that has been on Never Expire for years. There, storage can become significant, and it keeps growing.

Order the work by impact:

  1. Emit less.
  2. Move eligible log groups to Infrequent Access, which lowers the ingestion rate.
  3. Set retention deliberately.

Plug in your own volumes and regional prices before deciding where to start.

How do you find the log groups driving your CloudWatch Logs cost?

Before changing anything, find out where the bytes come from. Ingestion and storage are billed separately and are measured in different places, so rank log groups on each dimension.

Rank by ingestion with IncomingBytes

Every log group publishes an IncomingBytes metric in the AWS/Logs namespace, with LogGroupName as the dimension. Use the Sum statistic over a representative window, such as the last 30 days, so that a quiet weekend or a one-off incident doesn't distort the ranking. The metric counts uncompressed bytes, which is the basis for ingestion charges. That makes it the closest proxy for the ingestion line on your bill. Sort the results in descending order and note each group's share of the total.

Rank by storage with storedBytes

aws logs describe-log-groups returns a storedBytes field for each group. This is the volume currently held, after compression, and it is what storage charges are based on. The value is not updated in real time, so use it for ranking rather than for exact accounting. A group with a high storedBytes value but modest ingestion usually has no retention set, or one far longer than anyone needs.

Work the top of the list first

The two rankings rarely look flat. A handful of groups tend to account for most of the bytes, typically debug-level application logs, VPC Flow Logs, load balancer or API access logs, and chatty Lambda functions. Cutting 30% from the top three groups usually saves more than tuning the remaining hundreds. Start with the top few and stop when the next group's share stops justifying the engineering time.

#!/usr/bin/env bash
set -euo pipefail

REGION="us-east-1"   # placeholder: run once per region you use
START=$(date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%SZ)   # 30-day window smooths out spikes
END=$(date -u +%Y-%m-%dT%H:%M:%SZ)

echo "== Top 10 log groups by IncomingBytes (uncompressed, last 30 days) =="
aws logs describe-log-groups --region "$REGION" \
  --query 'logGroups[].logGroupName' --output text | tr '\t' '\n' |
while read -r lg; do
  # Daily Sum datapoints, added together. sum() of no datapoints returns 0.
  bytes=$(aws cloudwatch get-metric-statistics --region "$REGION" \
    --namespace AWS/Logs --metric-name IncomingBytes \
    --dimensions Name=LogGroupName,Value="$lg" \
    --start-time "$START" --end-time "$END" \
    --period 86400 --statistics Sum \
    --query 'sum(Datapoints[].Sum)' --output text)
  printf '%s\t%s\n' "$bytes" "$lg"
done | sort -t$'\t' -k1,1 -gr |
awk -F'\t' '{b[NR]=$1; n[NR]=$2; t+=$1}
  END {for (i=1; i<=NR && i<=10; i++)
    printf "%8.2f GiB  %5.1f%%  %s\n", b[i]/2^30, (t ? 100*b[i]/t : 0), n[i]}'

echo
echo "== Top 10 log groups by storedBytes (compressed, not real-time) =="
aws logs describe-log-groups --region "$REGION" \
  --query 'reverse(sort_by(logGroups, &storedBytes))[:10].[logGroupName, storedBytes, retentionInDays]' \
  --output table

A read-only AWS CLI script that ranks log groups by 30-day IncomingBytes with each group's share of the total, then lists the largest groups by storedBytes alongside their retention setting.

How can you reduce log ingestion at the source?

Ingestion is billed per gigabyte before retention or log class applies, so every byte removed in the application is a byte you never pay to ingest, store or scan.

Lower the default level. Production services rarely need DEBUG. Setting the default to INFO or WARN usually removes the bulk of volume, because debug output tends to fire inside loops and per-request paths.

Sample the success path. A health check or a 200 response logged on every request mostly repeats itself. Logging 1 in 100 keeps the shape of normal traffic visible.

Trim payloads. Full request and response bodies, base64 blobs and the same stack trace repeated across retries inflate line size quickly. Truncate bodies, log a payload hash or size instead, and emit a stack trace once per failure.

Tighten structured logs. JSON is worth keeping, but drop fields that are identical on every line, such as static service metadata, when a log group already identifies the source.

Count with metrics, not lines. Writing one log event per occurrence just to count it later is expensive. Emit a real metric, or use embedded metric format to publish one aggregated record per interval instead of one per event.

Treat infrastructure logs separately. VPC Flow Logs can use a custom format with fewer fields, capture only rejected traffic, or go to S3 instead of CloudWatch Logs.

The cost of these cuts is that the line you needed for a rare failure may be the one you dropped. Always log errors in full, propagate trace IDs so sampled requests can be correlated, and support raising verbosity at runtime per service or request. Each of these adds configuration and code paths that someone has to maintain and test.

import json, logging, os, random

class SuccessSampler(logging.Filter):
    """Keep every WARNING+ record; keep only a fraction of success-path records."""
    def __init__(self, rate):
        super().__init__()
        self.rate = rate
    def filter(self, record):
        if record.levelno >= logging.WARNING:
            return True  # never sample away errors or warnings
        if getattr(record, "success_path", False):
            return random.random() < self.rate
        return True

class CompactJson(logging.Formatter):
    MAX_BODY = 512  # truncate payloads; log the original size instead of the whole body
    def format(self, record):
        entry = {"level": record.levelname, "msg": record.getMessage(),
                 "trace_id": getattr(record, "trace_id", None)}  # lets sampled requests be correlated
        body = getattr(record, "body", None)
        if body is not None:
            entry["body"] = body[:self.MAX_BODY]
            entry["body_size"] = len(body)
        if record.exc_info:
            entry["exc"] = self.formatException(record.exc_info)  # one stack trace per failure
        return json.dumps(entry)  # no static service metadata: the log group identifies the source

handler = logging.StreamHandler()
handler.setFormatter(CompactJson())
handler.addFilter(SuccessSampler(float(os.environ.get("LOG_SAMPLE_RATE", "0.01"))))
log = logging.getLogger("orders")
log.addHandler(handler)
log.setLevel(os.environ.get("LOG_LEVEL", "INFO"))

log.info("order accepted", extra={"trace_id": "4bf92f3577b34da6", "success_path": True})
try:
    raise ValueError("card declined")
except ValueError:
    log.exception("charge failed", extra={"trace_id": "4bf92f3577b34da6", "body": "x" * 4096})

A Python standard-library logging setup that defaults to INFO, keeps about 1 in 100 success-path lines while keeping every warning and error, truncates large payloads, and attaches a trace ID so sampled requests can still be correlated.

When should you use the Infrequent Access log class, and when should you avoid it?

Once ingestion has been trimmed at the source, the remaining lever is the price paid per GB for what still arrives. The Infrequent Access log class charges a lower ingestion rate than Standard in exchange for fewer features. You can still query it with Logs Insights, but it does not support live tail, metric filters or subscription filters. Anything that needs to react to log lines as they arrive is ruled out.

The class is set when the log group is created and cannot be changed afterwards. Moving an existing workload means creating a new group, repointing every producer (agents, Lambda configuration, container log drivers), and leaving the old group to age out under its retention policy.

Use case Recommended class Reason
Audit trails queried during reviews Infrequent Access Read occasionally, ad hoc queries are enough
Verbose debug logs kept "just in case" Infrequent Access High volume, rarely read
Compliance archives Infrequent Access Retention matters, real-time access does not
Logs feeding metric filters or alarms Standard Metric filters are unsupported
Logs streamed to Lambda, Firehose or OpenSearch Standard Subscription filters are unsupported
Logs engineers tail during incidents Standard Live tail is unsupported

The risk comes later, when a group needs alerting. If an Infrequent Access group later needs an alarm, you have to create a Standard group and redirect producers to it. From then on, history is split across two groups. Investigations that span the cutover need queries against both, and you must track when each group's retention expires. Before choosing Infrequent Access, ask whether anyone is likely to want an alarm on that data within the retention window. If the answer is plausibly yes, the ingestion savings may not cover the cost of migrating later.

How do you set log retention deliberately and enforce it?

Every new log group defaults to Never Expire, so stored data, and the storage charge, grows indefinitely unless you change it. Retention is configured per log group, not per account, and only from a fixed set of allowed durations such as 1, 7, 30, 90, or 365 days. Values outside that set are rejected. Expired events are deleted automatically, which is what actually caps the storage line on the bill.

Audit and fix existing groups

A log group with no retention policy has no retentionInDays field in the aws logs describe-log-groups output. Filtering on that missing field gives you the list of groups set to Never Expire. You can then apply a policy to each one with aws logs put-retention-policy, passing the log group name and a valid duration. Run the audit in every region you use, because log groups are regional.

Define log groups in infrastructure-as-code

Some services create their own log groups. Lambda, for example, creates /aws/lambda/<function-name> on the first invocation, with Never Expire, and that group sits outside your templates and their defaults. To prevent this, declare the log group explicitly in your IaC with retention set, and deploy it before or alongside the function. If the group already exists, import it into the stack. Otherwise the stack's attempt to create the group fails because the name is already taken.

Pick durations for a reason

Base each duration on stated requirements: how far back incident responders need to look, how long security investigations need data, and what your compliance obligations specify. Cost alone is not a good basis. Write the chosen value down next to the log group definition so the next person knows why it was chosen. New groups appear constantly, so run the audit on a schedule or enforce retention as a check in your deployment pipeline. Without that, the savings erode quietly over time.

#!/usr/bin/env bash
set -euo pipefail

DEFAULT_DAYS="${DEFAULT_DAYS:-30}"
APPLY="${APPLY:-0}"

regions=$(aws ec2 describe-regions --query 'Regions[].RegionName' --output text)

for region in $regions; do
  # Groups set to Never Expire have no retentionInDays field.
  # The CLI follows pagination automatically, so this returns all groups.
  groups=$(aws logs describe-log-groups \
    --region "$region" \
    --query 'logGroups[?!retentionInDays].logGroupName' \
    --output text | tr '\t' '\n')

  for group in $groups; do
    if [[ "$APPLY" == "1" ]]; then
      aws logs put-retention-policy \
        --region "$region" \
        --log-group-name "$group" \
        --retention-in-days "$DEFAULT_DAYS"
      echo "set ${DEFAULT_DAYS}d: $region $group"
    else
      echo "never expires: $region $group"
    fi
  done
done

A bash audit that lists log groups with no retentionInDays in each region and, when APPLY=1, sets a deliberate retention on each one with aws logs put-retention-policy.

What are the alternatives for query cost and long-term log storage?

Logs Insights bills by the volume of data each query scans, not by the rows it returns. A query over 30 days of every log group costs far more than the same query over one hour of one service, even if both return ten lines. Set the time range first, select only the log groups you need, and filter early in the query.

Dashboards are where this cost hides. A Logs Insights widget reruns its query each time the dashboard refreshes. A wide query on a short refresh interval, left open on a wall screen, scans the same data over and over. For anything watched continuously, use metric filters or emitted metrics, which are cheap to graph. Keep Insights for investigation.

If you must keep logs longer than operational needs justify, move them out of CloudWatch. Export tasks copy a log group's data to S3 in batches. They are not real time and suit periodic archiving. Subscription filters stream events as they arrive to Kinesis, Firehose or Lambda. Both only move data you have already paid to ingest. The original ingestion charge stays on the bill.

Option What it reduces What it adds Ingestion charge removed?
Scoped Insights queries Data scanned per query Query discipline, review of dashboards No
Metric filters for dashboards Repeated Insights scans Metric costs, upfront filter design No
Export task to S3 Long-term CloudWatch storage Export scheduling, S3 lifecycle rules, bucket access policies No
Subscription filter streaming Long-term CloudWatch storage Transfer and processing charges, delivery pipeline to operate, a separate query engine, access control No

Moving logs to S3 shifts cost and work rather than removing it. You now own lifecycle policies, encryption, access control for sensitive log content, and query tooling. Choose it when retention requirements are long and access is rare.

Pricing varies by region and changes over time. Treat any estimate here as a model to fill in with your current rates, not a budget figure.

How can this work save engineering time, not just money?

Several of these changes reduce recurring effort as well as the bill.

  • Ranking first keeps the effort small. The IncomingBytes and storedBytes rankings tell you which few log groups are worth touching. Without them, teams tend to review every log group or argue about which service is noisy. With them, the work is limited to a short list, and you can stop when the remaining groups are too small to matter.
  • Retention in IaC replaces repeated cleanup. When every log group is declared with a retention value, nobody has to find and fix Never Expire groups by hand later. A scheduled audit or a pipeline check catches the exceptions, such as auto-created Lambda groups, without anyone having to remember to look.
  • Less noise makes incidents faster to work. When DEBUG output, repeated success lines and oversized payloads are gone, searches and Logs Insights queries cover less data. Results are easier to read, and engineers spend less time filtering out irrelevant lines while a service is failing. Keeping errors in full and propagating trace IDs means the lines that matter are still there.
  • Shared logging configuration applies once. A sampling filter and compact formatter, like the Python example above, can live in a shared library or service template. Each new service gets sensible defaults without its owners having to tune logging from scratch.
  • Metrics instead of log-derived counts simplify dashboards. Graphs built on metric filters or emitted metrics don't depend on long-running queries, and they are easier to alarm on than an Insights query someone has to rerun.
  • Choosing the log class carefully avoids a migration later. Asking up front whether a group will need alarms or subscriptions prevents the work of creating a Standard group, repointing producers and querying split history across a cutover.

The time saved depends on how many log groups and services you have and how often people currently clean up by hand. The pattern holds regardless of scale: decisions encoded in templates, shared libraries and scheduled checks stop being tasks someone has to repeat.

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 .env by 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.