> ## 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 metrics to Costory and import custom usage metrics.

Connect AWS CloudWatch to import 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.

<Tabs>
  <Tab title="Manual setup">
    1. Create an AWS CloudWatch integration in **Integrations**:
       a. In AWS, attach the following policy to the existing federated IAM role that Costory uses:

       ```
       {
       "Version": "2012-10-17",
       "Statement": [
           {
           "Sid": "CloudWatchReadForCostory",
           "Effect": "Allow",
           "Action": [
               "cloudwatch:ListMetrics",
               "cloudwatch:GetMetricData",
               "cloudwatch:GetMetricStatistics"
           ],
           "Resource": "*"
           }
       ]
       }
       ```

       b. Make sure the new policy is attached to the federated IAM role for Costory.
    2. In Costory, go to **Metrics > Import new metrics datasource > AWS CloudWatch**.
    3. Provide the CloudWatch query, aggregation, and optional group-by fields.

       a. You should import the metric as an AWS CloudWatch insight query:

       ```
       SELECT SUM(BucketSizeBytes) FROM SCHEMA("AWS/S3", BucketName,StorageType) GROUP BY BucketName
       ```

           <Frame caption="AWS CloudWatch insight query">
             <img src="https://mintcdn.com/costory/hVz2Fv0xDomX3evm/setup/usage-metrics/cloud-watch-example.png?fit=max&auto=format&n=hVz2Fv0xDomX3evm&q=85&s=3c2cad6560d28b17df2cbc038ad638d5" alt="AWS CloudWatch insight query" width="1199" height="616" data-path="setup/usage-metrics/cloud-watch-example.png" />
           </Frame>

           <Frame caption="AWS CloudWatch metric configuration in Costory">
             <img src="https://mintcdn.com/costory/hVz2Fv0xDomX3evm/setup/usage-metrics/cloud-watch-setup-2.png?fit=max&auto=format&n=hVz2Fv0xDomX3evm&q=85&s=1c6e8d19f7f3f5aa0dfc9bfc3b26d0a9" alt="AWS CloudWatch metric in Costory" width="1365" height="825" data-path="setup/usage-metrics/cloud-watch-setup-2.png" />
           </Frame>

       b. After a few seconds, the metric will be available in Costory. Common examples you can import:

       * **S3 storage size**: total bytes per bucket (`AWS/S3` `BucketSizeBytes`)
       * **HTTP request volume**: number of requests per API, ALB, or distribution (e.g. `AWS/ApiGateway`, `AWS/ApplicationELB`, `AWS/CloudFront`)
       * **CPU and memory utilization**: average CPU/memory by service, cluster, or Auto Scaling group (`AWS/EC2`, `AWS/ECS`, `AWS/EKS`)
       * **Queue depth and throughput**: SQS queue length, messages sent/received (`AWS/SQS`)
       * **Database load**: connections, CPU, IOPS for RDS or Aurora (`AWS/RDS`)

    <Frame caption="AWS CloudWatch metric in Costory">
      <img src="https://mintcdn.com/costory/hVz2Fv0xDomX3evm/setup/usage-metrics/result-cloud-watch.png?fit=max&auto=format&n=hVz2Fv0xDomX3evm&q=85&s=9e65ae8019d7f89b2acd973959656818" alt="AWS CloudWatch metric in Costory" width="1689" height="820" data-path="setup/usage-metrics/result-cloud-watch.png" />
    </Frame>
  </Tab>

  <Tab title="Terraform">
    Terraform support for AWS CloudWatch usage metrics is not available yet. If you want to manage this integration as code, contact us so we can prioritize it.
  </Tab>
</Tabs>
