Sub topic 17
Cross-account and cross-region observability
This chapter assumes you can create alarms, query logs, and build dashboards in a single account and region. It also assumes you know basic IAM and AWS Organizations ideas, such as an organization ID and member accounts. Here you will see how to view and alarm on telemetry (metrics, logs, and traces) that lives in other accounts and regions.
Why centralize
Most real workloads span several AWS accounts, often one per environment or team, and sometimes several regions. Without centralization, an on-call engineer must switch accounts and regions to follow one request. CloudWatch gives you two scopes to think about:
- Account scope: CloudWatch cross-account observability lets one monitoring account see metrics, log groups, and traces from many source accounts.
- Region scope: CloudWatch data stays in the region where it was created. Cross-region views are assembled by the console or by widgets that name a region. Data is not copied to another region.
How cross-account observability works
The feature is built on the Observability Access Manager (OAM). It uses two resources:
- A sink is created in the monitoring account. It is the receiving point and carries a policy that says which accounts may connect.
- A link is created in each source account. It points to a sink and lists the resource types to share.
Sinks and links are regional. A link in us-east-1 connects only to a sink in us-east-1. To observe several regions, create a sink in each region of the monitoring account and a link in each region of every source account.
The data is not copied. The monitoring account reads it in place, and each source account keeps ownership of its metrics and logs.
Setting up a sink
In the monitoring account, create the sink:
aws oam create-sink --name central-monitoring --region us-east-1The command returns the sink ARN. Next, attach a policy that decides who may link. This policy admits every account in one organization and allows only metrics and log groups:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": ["oam:CreateLink", "oam:UpdateLink"],
"Resource": "*",
"Condition": {
"ForAllValues:StringEquals": {
"oam:ResourceTypes": ["AWS::CloudWatch::Metric", "AWS::Logs::LogGroup"]
},
"StringEquals": { "aws:PrincipalOrgID": "o-exampleorgid" }
}
}
]
}Save it as sink-policy.json and apply it:
aws oam put-sink-policy \
--sink-identifier arn:aws:oam:us-east-1:111122223333:sink/11111111-2222-3333-4444-555555555555 \
--policy file://sink-policy.json \
--region us-east-1To admit specific accounts instead, replace the organization condition with a Principal that lists the account IDs.
Linking a source account
In each source account, create a link that names the sink and the resource types to share:
aws oam create-link \
--label-template '$AccountName' \
--resource-types AWS::CloudWatch::Metric AWS::Logs::LogGroup \
--sink-identifier arn:aws:oam:us-east-1:111122223333:sink/11111111-2222-3333-4444-555555555555 \
--region us-east-1The label template controls how the monitoring account displays the source. $AccountName is replaced with the account's name. The resource types in the link must be allowed by the sink policy, or creation fails.
Using the shared data
Once linked, the monitoring account can use source data in three ways.
Dashboards
A metric widget can name an account and region for each metric. This dashboard body graphs CPU from an instance in another account and region:
{
"widgets": [
{
"type": "metric",
"x": 0, "y": 0, "width": 12, "height": 6,
"properties": {
"title": "Orders API CPU (account 444455556666, eu-west-1)",
"region": "us-east-1",
"stat": "Average",
"period": 300,
"metrics": [
["AWS/EC2", "CPUUtilization", "InstanceId", "i-0123456789abcdef0",
{ "accountId": "444455556666", "region": "eu-west-1" }]
]
}
}
]
}The widget-level region is the default. The region inside the options object overrides it for that one metric, which lets one graph combine regions.
Alarms
A metric alarm in the monitoring account can watch a source account's metric. Use the --metrics form, where each query may carry an AccountId. Save this as metrics.json:
[
{
"Id": "cpu",
"AccountId": "444455556666",
"MetricStat": {
"Metric": {
"Namespace": "AWS/EC2",
"MetricName": "CPUUtilization",
"Dimensions": [{ "Name": "InstanceId", "Value": "i-0123456789abcdef0" }]
},
"Period": 300,
"Stat": "Average"
},
"ReturnData": true
}
]aws cloudwatch put-metric-alarm \
--alarm-name orders-high-cpu \
--metrics file://metrics.json \
--evaluation-periods 3 \
--datapoints-to-alarm 2 \
--threshold 80 \
--comparison-operator GreaterThanOrEqualToThreshold \
--treat-missing-data notBreaching \
--alarm-actions arn:aws:sns:us-east-1:111122223333:ops-alerts \
--region us-east-1The alarm, its state, and its actions live in the monitoring account and in the region where you created it. The SNS topic must be in that same account and region.
Logs Insights
In the monitoring account console you can pick log groups from linked accounts in one query. From the CLI, pass log group ARNs:
aws logs start-query \
--log-group-identifiers arn:aws:logs:eu-west-1:444455556666:log-group:/app/web \
--start-time 1795720800 \
--end-time 1795724400 \
--query-string 'fields @timestamp, @message | filter @message like /ERROR/ | limit 20' \
--region eu-west-1Run the query in the region that holds the log group. A single query cannot span regions.
Limits and gotchas
- Alarms are regional. An alarm evaluates metrics in its own region. To alarm on a metric from another region, create the alarm in that region, or in a monitoring account with a link in that region.
- Composite alarms combine alarms in the same account and region. If you want one composite across several sources, create the member alarms in the monitoring account first.
- Sharing is one-way and read-only. The monitoring account cannot change source resources through the link.
- Metric filters and the agent still run in the source account. A metric filter creates its metric in the source account, and the link then makes it visible centrally.
- Older method. Before OAM, the console shared data through an IAM role named
CloudWatch-CrossAccountSharingRole. It still works for dashboards, but OAM is the recommended approach and also supports alarms and Logs Insights. - Cost. Alarms and dashboards you create in the monitoring account are billed there. Check the CloudWatch pricing page for any charge tied to linked telemetry before you roll out to many accounts.
Choosing a design
| Need | Approach |
|---|---|
| One pane across many accounts, one region | One sink, a link in each source account |
| Several regions | One sink and one set of links per region |
| Graph two regions together | Per-metric `region` option in a dashboard |
| Alert across accounts | Alarm in the monitoring account using `AccountId` |
| Keep a copy of data elsewhere | Export with metric streams or log subscriptions, which is a different feature |
Exercise
Your monitoring account has a sink in us-east-1. A source account has a link to it, and you want to alarm on a metric that the source account publishes in eu-west-1. Why does this fail, and what do you add?
Show answer
Sinks and links are regional, and alarms read metrics in their own region. The us-east-1 link shares only us-east-1 data. Create a sink in eu-west-1 in the monitoring account, create a link in eu-west-1 in the source account, and create the alarm in eu-west-1, with the SNS topic in that region too.
Exercise
A source account's link creation fails with an authorization error. The link requests AWS::CloudWatch::Metric, AWS::Logs::LogGroup, and AWS::XRay::Trace. The sink policy allows only metrics and log groups. What is the fix?
Show answer
Either remove AWS::XRay::Trace from the link's resource types, or update the sink policy so that oam:ResourceTypes also allows AWS::XRay::Trace. The link may request only resource types that the sink policy permits.