Lesson 3 of 5 CloudWatch Metrics, Alarms and Dashboards

Streaming Metrics with CloudWatch Metric Streams

Some organisations analyse or store metrics outside CloudWatch: in a data lake, in a third-party observability platform or for long-term retention beyond 15 months. CloudWatch metric streams deliver metrics continuously with low latency through Amazon Data Firehose. This lesson explains how metric streams work, their destinations, formats and filters, and how they compare with polling the API.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how a metric stream delivers metrics through Amazon Data Firehose.
  • Describe the destinations, output formats and filters of metric streams.
  • Compare metric streams with polling GetMetricData and with cross-account observability.
  • Explain the IAM role a metric stream needs and how stream delivery is monitored and troubleshot.
  • Design a metric stream for long-term storage in Amazon S3 and analysis with Athena.

How Metric Streams Work

A metric stream continuously sends metric updates from CloudWatch to an Amazon Data Firehose delivery stream (formerly Kinesis Data Firehose), typically within two to three minutes of the data point. Firehose then buffers, optionally transforms with Lambda, compresses and delivers the data to its destination. A stream can include all metrics in an account and Region or a filtered subset, and with cross-account observability a stream in a monitoring account can include metrics from linked source accounts.

Common destinations, all through Firehose, are Amazon S3 for a metrics data lake, third-party observability partners such as Datadog, Dynatrace, New Relic, Splunk and Sumo Logic using HTTP endpoint delivery, and Amazon OpenSearch Service. The console's quick setup creates the Firehose stream, IAM roles and S3 bucket for common configurations.

Formats, Filters and Statistics

Metric streams output data in JSON or OpenTelemetry format (versions 0.7 and 1.0), with OpenTelemetry being the standard for partner tools. Each record contains the namespace, metric name, dimensions, timestamp, unit and the statistics Minimum, Maximum, Sum and SampleCount for one minute. Additional statistics, such as p99 percentiles, can be configured for selected metrics at extra cost.

Include and exclude filters select namespaces or specific metric names, so that only relevant metrics are streamed, which controls cost because metric streams are charged per metric update. Filters by namespace, such as including only AWS/EC2, AWS/ApplicationELB and a custom namespace, are typical.

Choosing Metric Streams

There are three ways to get metrics out of an account or to a central place. They are compared below.

Metric streams
LatencyMinutes, continuous
DestinationFirehose to S3, partners, OpenSearch
Scale and throttlingNo API limits to manage
Typical useThird-party tools, data lakes, long-term retention
Choose when Continuous export of many metrics outside CloudWatch.
Polling GetMetricData
LatencyDepends on polling frequency
DestinationAny code that calls the API
Scale and throttlingAPI quotas and pagination
Typical useSmall or occasional exports
Choose when Occasional, small queries.
Cross-account observability
LatencyNear real time in CloudWatch
DestinationA CloudWatch monitoring account
Scale and throttlingNot applicable
Typical useCentral CloudWatch dashboards and alarms
Choose when Centralising monitoring within CloudWatch.

Metric streams in exam scenarios

When a scenario requires sending CloudWatch metrics to a third-party monitoring tool or to S3 in near real time with the least operational overhead, the answer is a CloudWatch metric stream to Amazon Data Firehose, not a Lambda function that polls the API on a schedule.

Sort into groups

Export or centralise metrics?

Exam skills 4.1.3

Choose how to get metrics to the place they are needed.

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

Creating, Operating and Troubleshooting a Stream

A metric stream needs three things before it can be created: a Firehose stream with its destination, and an IAM role that CloudWatch assumes to write to it. The role trusts the service principal streams.metrics.cloudwatch.amazonaws.com and allows firehose:PutRecord and firehose:PutRecordBatch on that Firehose stream only. Firehose has its own role to write to S3 or to call a partner endpoint. The following command creates a filtered stream in a monitoring account, including metrics from its linked source accounts.

aws cloudwatch put-metric-stream \
  --name central-metrics \
  --firehose-arn arn:aws:firehose:eu-west-1:111122223333:deliverystream/metrics-to-s3 \
  --role-arn arn:aws:iam::111122223333:role/MetricStreamToFirehose \
  --output-format opentelemetry1.0 \
  --include-filters Namespace=AWS/EC2 Namespace=AWS/ApplicationELB Namespace=Checkout \
  --include-linked-accounts-metrics

A stream sends only data points published after it starts; it does not backfill history, so historical data must be exported separately with GetMetricData if needed. A stream can be stopped and started with stop-metric-streams and start-metric-streams, for example while a destination is being migrated, and it can be defined in CloudFormation as AWS::CloudWatch::MetricStream together with the Firehose stream and roles.

A stream is monitored like any other component. CloudWatch publishes metrics about each stream in the AWS/CloudWatch/MetricStreams namespace, including MetricUpdate (the number of updates sent) and PublishErrorRate (the proportion of failed writes to Firehose). Firehose publishes delivery metrics such as DeliveryToS3.Success and DeliveryToHttpEndpoint.Success, and records delivery failures in its error logs, with failed records written to an S3 backup location. The common faults and their causes are summarised below.

SymptomLikely causeRemedy
PublishErrorRate above zeroThe stream's role lacks Firehose permissions, or the Firehose stream was deletedCorrect the role policy or the Firehose ARN
Stream healthy, but no data at the partnerFirehose cannot reach or authenticate to the HTTP endpointCheck the endpoint URL, access key and Firehose error logs
Expected metrics missingInclude or exclude filters do not match the namespace or metric nameReview the filters; namespaces are case-sensitive
Metrics from other accounts missingLinked-account metrics are not included, or the accounts are not linkedEnable linked-account metrics and check the observability links
True or false

Running a metric stream

Exam skills 4.1.3

Check four facts about creating and operating metric streams.

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

A Metrics Data Lake

A company must retain one-minute metrics for five years for capacity planning, beyond CloudWatch's retention, and analyse them with SQL.

  1. Stream

    Create a metric stream in the monitoring account, including metrics from linked source accounts, filtered to the required namespaces, in JSON format with p99 additional statistics for latency metrics.

  2. Delivery

    Firehose buffers and delivers compressed records to an S3 bucket partitioned by date, converting to Parquet to reduce query cost.

  3. Lifecycle

    An S3 lifecycle rule moves data older than 90 days to S3 Glacier Instant Retrieval and expires it after five years.

  4. Analysis

    Define an Athena table over the bucket with partition projection, and build Quick Sight dashboards on Athena queries.

Check yourself

A metric stream is costing more than expected. What setting reduces cost without losing the needed data?

Show answer

Include filters limiting the stream to the namespaces or metrics that are needed, and removing additional statistics that are not used, because metric streams are charged per metric update.

Exam Tips

Remember for the exam

  • Metric streams send metrics continuously to Amazon Data Firehose, which delivers to S3, OpenSearch or third-party HTTP endpoints.
  • Output formats are JSON or OpenTelemetry; include and exclude filters by namespace or metric control cost; additional statistics such as percentiles are optional.
  • Prefer metric streams to scheduled GetMetricData polling for continuous export.
  • Use S3 with Athena for long-term metric retention beyond 15 months.
  • The stream's role trusts streams.metrics.cloudwatch.amazonaws.com and allows firehose:PutRecord(Batch); streams do not backfill; watch PublishErrorRate in AWS/CloudWatch/MetricStreams.