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 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.
Export or centralise metrics?
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-metricsA 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.
| Symptom | Likely cause | Remedy |
|---|---|---|
| PublishErrorRate above zero | The stream's role lacks Firehose permissions, or the Firehose stream was deleted | Correct the role policy or the Firehose ARN |
| Stream healthy, but no data at the partner | Firehose cannot reach or authenticate to the HTTP endpoint | Check the endpoint URL, access key and Firehose error logs |
| Expected metrics missing | Include or exclude filters do not match the namespace or metric name | Review the filters; namespaces are case-sensitive |
| Metrics from other accounts missing | Linked-account metrics are not included, or the accounts are not linked | Enable linked-account metrics and check the observability links |
Running a metric stream
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.
-
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.
-
Delivery
Firehose buffers and delivers compressed records to an S3 bucket partitioned by date, converting to Parquet to reduce query cost.
-
Lifecycle
An S3 lifecycle rule moves data older than 90 days to S3 Glacier Instant Retrieval and expires it after five years.
-
Analysis
Define an Athena table over the bucket with partition projection, and build Quick Sight dashboards on Athena queries.
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.