Lesson 5 of 6 Data Transfer and Cost-Optimized Design

Keeping Observability Costs Under Control

This lesson explains the main CloudWatch cost drivers and how log levels, log classes, retention, metric aggregation and sampling reduce them.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify the largest observability cost drivers.
  • Describe how retention, log classes and log levels reduce log costs.
  • Explain how metric dimensions and the embedded metric format affect cost.

Logs

Log ingestion is usually the largest observability cost. Applications should log at appropriate levels in production (Lambda advanced logging controls set the level without code changes), sample verbose logs, and drop noise such as health checks at the source or in a log router. The Infrequent Access log class costs about half as much per GB ingested for logs that are kept for investigations but rarely queried interactively. Every log group needs a retention period, because the default is never to expire; logs kept for years belong in S3 with lifecycle rules to Glacier storage classes.

Select all that apply

Cutting log costs

Exam skills 3.4.5

Identify changes that reduce CloudWatch Logs costs.

Log in to try this activity Interactive activities are free with an account.

Metrics and traces

Custom metrics are charged per unique combination of name and dimensions, so high-cardinality dimensions such as user or request IDs multiply costs; aggregate before publishing and keep per-request detail in logs. The embedded metric format creates metrics from structured logs without separate API calls, standard resolution is cheaper than high resolution, and metric math derives values without storing them. Traces are sampled rather than recorded for every request.

Cost driverReduction
Log groups that never expireRetention on every group, archive to S3
Verbose logs rarely queriedInfrequent Access log class, lower log levels
High-cardinality custom metricsAggregate by service and operation
Separate PutMetricData callsEmbedded metric format
Tracing every requestSampling rules

Governing observability spend

  • Enforce retention on new log groups with an EventBridge rule or Config remediation.
  • Tag log groups and use cost allocation to show each team its observability cost.
  • Review the most expensive log groups and metrics regularly in Cost Explorer and CUR.
  • Keep central logs short in CloudWatch and long in S3.
Worked example

A runaway logging bill

A company's CloudWatch bill exceeds its EC2 bill. 2,000 log groups have no retention, Lambda functions log at DEBUG in production, and a latency metric uses a CustomerId dimension with 1.5 million values.

The team sets retention on every group through automation, moves audit and debug groups to the Infrequent Access class, and sets production Lambda log levels to WARN.

The latency metric is republished by service and operation only, with customer detail left in structured logs that Logs Insights can query when needed. The bill falls by about 70%.

Check yourself

What is the default retention of a CloudWatch Logs log group, and why does it matter for cost?

Show answer

Never expire. Without a retention setting, stored logs grow indefinitely, so every log group needs an explicit retention period.

Exam Tips

Remember for the exam

  • Log storage grows without limit: set retention on every log group and archive long-term logs to S3.
  • Logs rarely queried interactively: Infrequent Access log class.
  • Custom metric costs explode: remove high-cardinality dimensions.
  • Metrics from logs without API calls: embedded metric format.