> ## 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.

# S3 metrics

> Connect Parquet files from AWS S3 as external metrics in Costory. Scan a bucket prefix, then query discovered metrics in Advanced Explorer.

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

Costory mirrors Parquet files under a prefix and exposes each as a metric in Advanced Explorer. Files are mirrored to Google Cloud Storage and exposed through BigQuery external tables. You can trigger a sync manually at any time.

Costory scans only the prefix root plus one directory level. A directory of `part-*.parquet` files counts as one metric. Every other `.parquet` file is its own metric, including dated snapshots. Hive partitions (`dt=2026-08-01/`) are not supported. The maximum is 50 metrics per bucket.

![Connect an S3 bucket form with scan rules, Role ARN, bucket name, and optional prefix](https://mintcdn.com/costory/7N_qRRx_7ACcj7QT/images/external-metrics/connect-s3-metrics.png?fit=max\&auto=format\&n=7N_qRRx_7ACcj7QT\&q=85\&s=bf4db8797dd62ae746b9538a7f8e84bd)

Connect an S3 bucket: how files become metrics, then Role ARN, bucket, and prefix

![Lower half of Connect an S3 bucket with the S3 read policy, Force validate, Validate, and Save connection](https://mintcdn.com/costory/7N_qRRx_7ACcj7QT/images/external-metrics/connect-s3-metrics-bottom.png?fit=max\&auto=format\&n=7N_qRRx_7ACcj7QT\&q=85\&s=66a57c06f141d51fec024d05b62a1a70)

S3 metrics connect screen: S3 read policy, prefix, Force validate, and Save connection

> [tab] Manual setup
>
> **1. Store Parquet files in S3**
>
> Put metric files under a bucket prefix. Keep the layout to the prefix root and one directory. Do not rely on Hive-style partitions (`dt=2026-08-01/...`).
>
> **2. Create a read-only IAM role**
>
> Create an IAM role with read-only S3 access on that bucket and prefix, plus a web identity trust for Costory. Use the same federated trust as [AWS billing](https://docs.costory.io/setup/billing/aws.md). Copy the trust policy from the Costory connect screen.
>
> **3. Open the AWS tile**
>
> Go to [Integrations](https://app.costory.io/integration), click **+ Add integration**, then under **External metric** choose **AWS**. Pick **S3 metrics**.&#x20;
>
> **4. Enter connection details**
>
> Fill **Connection name**, **Role ARN**, and **Bucket name**. **Prefix** is optional. Click **Validate**, then **Save connection**. Use **Force validate** if you need to re-check the role and bucket after a failed attempt.
>
> **5. Query in Advanced Explorer**
>
> Click **Explore your data**, switch to **Advanced**, then **+ Add Metric**. Open **integrations** and pick the S3 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. Hive partitions are not supported. Costory stops at 50 metrics per bucket.
>
> ## How files become metrics
>
> | Layout | Result |
> | - | - |
> | Directory of `part-*.parquet` files | One metric |
> | Any other `.parquet` file | Its own metric, including dated snapshots |
> | Hive partitions (`dt=…/`) | Not supported |
> | Deeper than prefix root + one directory | Not scanned |

> [tab] Terraform
>
> ```hcl theme={null}
> terraform {
>   required_providers {
>     costory = {
>       source  = "costory-io/costory"
>       version = ">= 0.1.0"
>     }
>   }
> }
>
> variable "costory_token" {
>   type        = string
>   description = "Costory API token."
>   sensitive   = true
> }
>
> variable "s3_bucket_name" {
>   type        = string
>   description = "S3 bucket containing parquet metrics files."
> }
>
> variable "s3_prefix" {
>   type        = string
>   description = "S3 key prefix for parquet files."
>   default     = ""
> }
>
> variable "role_arn" {
>   type        = string
>   description = "IAM role ARN for Costory to assume (must match arn:aws:iam::)."
> }
>
> provider "costory" {
>   token = var.costory_token
> }
>
> resource "costory_metrics_datasource_s3_parquet" "main" {
>   name        = "AWS S3 Metrics"
>   bucket_name = var.s3_bucket_name
>   prefix      = var.s3_prefix
>   role_arn    = var.role_arn
>
>   metrics_definition {
>     metric_name  = "Usage"
>     gap_filling  = "ZERO"
>     aggregation  = "SUM"
>     value_column = "usage_amount"
>     date_column  = "usage_start_date"
>     dimensions   = ["service", "region"]
>     unit         = "count"
>   }
> }
>
> resource "costory_metrics_datasource_s3_parquet" "multiple" {
>   name        = "Multiple metrics"
>   bucket_name = var.s3_bucket_name
>   prefix      = var.s3_prefix
>   role_arn    = var.role_arn
>
>   metrics_definition {
>     metric_name  = "Nbr of R&D teams"
>     gap_filling  = "FORWARD_FILL"
>     aggregation  = "SUM"
>     value_column = "nbr_rd_teams"
>     date_column  = "usage_start_date"
>     unit         = "count"
>   }
>   metrics_definition {
>     metric_name  = "Organizations"
>     gap_filling  = "FORWARD_FILL"
>     aggregation  = "SUM"
>     value_column = "nbr_organizations"
>     date_column  = "usage_start_date"
>     unit         = "count"
>   }
> }
> ```

## Related pages

> [card] [AWS CloudWatch](https://docs.costory.io/setup/usage-metrics/aws-cloudwatch.md)
>
> Connect CloudWatch on the same AWS tile.

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

> [card] [Google Sheets](https://docs.costory.io/setup/usage-metrics/google-sheet.md)
>
> Connect numeric columns from a spreadsheet instead.


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