> ## Documentation Index
> Fetch the complete documentation index at: https://docs.costory.io/llms.txt
> Use this file to discover all available pages before exploring further.

# AWS CloudWatch

> Connect AWS CloudWatch as an external metric in Costory. Attach a CloudWatch read policy and trust policy, then query metrics in Advanced Explorer.

Connect AWS CloudWatch to query custom usage metrics, such as S3 storage size, request counts, CPU usage, or queue depth. Costory pairs these with billing data so you can build unit economics.

On **Add integration**, the **AWS** tile is **CloudWatch metrics / Parquet files from S3**. Choose **CloudWatch** on that tile. For Parquet files, see [S3 metrics](https://docs.costory.io/setup/usage-metrics/s3-parquet.md).

![Add integration AWS choice between CloudWatch and S3 metrics](https://mintcdn.com/costory/7N_qRRx_7ACcj7QT/images/external-metrics/connect-aws-metrics-choice.png?fit=max\&auto=format\&n=7N_qRRx_7ACcj7QT\&q=85\&s=b94f8f3a5164c042b0252ecd00012c46)

AWS External metric choice: CloudWatch or S3 metrics

![Connect AWS CloudWatch form with IAM policy JSON, Role ARN, and AWS region](https://mintcdn.com/costory/7N_qRRx_7ACcj7QT/images/external-metrics/connect-cloudwatch.png?fit=max\&auto=format\&n=7N_qRRx_7ACcj7QT\&q=85\&s=f287f50dbfe885ea0836729f79e58ddf)

Connect AWS CloudWatch: read policy on the left, Role ARN and region on the right

![Lower half of Connect AWS CloudWatch with the custom trust policy, Role ARN, region, Validate, and Save connection](https://mintcdn.com/costory/7N_qRRx_7ACcj7QT/images/external-metrics/connect-cloudwatch-bottom.png?fit=max\&auto=format\&n=7N_qRRx_7ACcj7QT\&q=85\&s=311d067836425c94c7c212e05990c72d)

CloudWatch connect screen: IAM trust policy and Validate before Save connection

> [tab] Manual setup
>
> **1. Create the CloudWatch read policy**
>
> In IAM, create a customer managed policy from this JSON. Attach it to the role after you set up trust.
>
> ```json theme={null}
> {
>   "Version": "2012-10-17",
>   "Statement": [
>     {
>       "Sid": "CloudWatchReadForCostory",
>       "Effect": "Allow",
>       "Action": [
>         "cloudwatch:ListMetrics",
>         "cloudwatch:GetMetricData",
>         "cloudwatch:GetMetricStatistics"
>       ],
>       "Resource": "*"
>     }
>   ]
> }
> ```
>
> **2. Create the trust policy**
>
> Create or edit an IAM role Costory can assume. Use the same web identity trust as [AWS billing](https://docs.costory.io/setup/billing/aws.md): federated access for Costory's GCP service account. Copy the trust policy from the Costory connect screen, then attach the CloudWatch read policy to that role.
>
> **3. Open the AWS tile**
>
> Go to [Integrations](https://app.costory.io/integration), click **+ Add integration**, then under **External metric** choose **AWS**. Pick **CloudWatch** (not S3 metrics).&#x20;
>
> **4. Enter connection details**
>
> Fill **Connection name**, **Role ARN**, and **AWS region**. Click **Validate**, then **Save connection**.
>
> **5. Query in Advanced Explorer**
>
> Click **Explore your data**, switch to **Advanced**, then **+ Add Metric**. Open **integrations** and pick the CloudWatch source. See [Query after you connect](https://docs.costory.io/setup/usage-metrics#query-after-you-connect).
>
> > [!NOTE]
> >
> > **Save connection** stays disabled until validation succeeds.
>
> ## Example CloudWatch metrics
>
> After you connect, pick a CloudWatch metric in Advanced Explorer. One common series is total bytes per S3 bucket (`AWS/S3` `BucketSizeBytes`).
>
> ```
> SELECT SUM(BucketSizeBytes) FROM SCHEMA("AWS/S3", BucketName,StorageType) GROUP BY BucketName
> ```
>
> ![CloudWatch query selecting SUM of BucketSizeBytes grouped by BucketName](https://mintcdn.com/costory/hVz2Fv0xDomX3evm/setup/usage-metrics/cloud-watch-example.png?fit=max\&auto=format\&n=hVz2Fv0xDomX3evm\&q=85\&s=3c2cad6560d28b17df2cbc038ad638d5)
>
> CloudWatch metric query for S3 bucket size
>
> Other series teams query:
>
> * Total bytes per S3 bucket (`AWS/S3` `BucketSizeBytes`)
> * Request counts on API Gateway, ALB, or CloudFront (`AWS/ApiGateway`, `AWS/ApplicationELB`, `AWS/CloudFront`)
> * Average CPU or memory by service, cluster, or Auto Scaling group (`AWS/EC2`, `AWS/ECS`, `AWS/EKS`)
> * SQS queue length and messages sent or received (`AWS/SQS`)
> * RDS or Aurora connections, CPU, and IOPS (`AWS/RDS`)
>
> ![CloudWatch usage metric visualized in Costory](https://mintcdn.com/costory/hVz2Fv0xDomX3evm/setup/usage-metrics/result-cloud-watch.png?fit=max\&auto=format\&n=hVz2Fv0xDomX3evm\&q=85\&s=9e65ae8019d7f89b2acd973959656818)
>
> CloudWatch metric series in Costory after the query returns data

> [tab] Terraform
>
> Not supported.

## Related pages

> [card] [S3 metrics](https://docs.costory.io/setup/usage-metrics/s3-parquet.md)
>
> Connect Parquet files from S3 on the same AWS tile.

> [card] [Metrics Correlation](https://docs.costory.io/setup/usage-metrics)
>
> Query external metrics in Advanced Explorer.

> [card] [Unit Economics](https://docs.costory.io/features/unit-economics.md)
>
> Divide cloud cost by a CloudWatch metric.

> [card] [AWS Billing](https://docs.costory.io/setup/billing/aws.md)
>
> Connect CUR 2.0 with the same federated IAM trust.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.