Skip to content

Tenant-Level Cost Attribution Without the Rebuild: A CUR 2.0 Pattern

12 minute read
Content level: Intermediate
0

Multi-tenant SaaS providers running all workloads under a single AWS Organization with one Organizational Unit (OU) per tenant hit a common wall: CUR 2.0 has no native OU column, so tenant-level cost attribution needs custom plumbing. This article shows how to build a lightweight, self-refreshing pipeline that pulls OU membership from the Organizations API into a mapping CSV, joins it to CUR at query time in Athena or Snowflake, and delivers accurate tenant-level chargeback today across history

Segmenting Tenant-Level Cost in a Single-Org, OU-per-Tenant Model


A recurring question I hear from customers running multi-tenant platforms on AWS is deceptively simple: "How much does each tenant actually cost us?" It sounds like a reporting problem. It is really an architecture-and-data problem - and the single decision that decides the answer is made long before anyone opens Cost Explorer.

The decision that matters: the tenant-segmentation model you choose at account-consolidation time determines whether tenant chargeback is a five-minute query or a multi-month rebuild. Get it right early and attribution is a join. Get it wrong and you are backfilling mappings under deadline pressure while a leadership review waits on numbers that don't reconcile.

This post walks through the pattern I worked through with a customer running a multi-tenant SaaS platform under a single AWS Organization, with one Organizational Unit (OU) per tenant. The customer is kept fully generic; the approach ports cleanly to any single-Org, OU-per-tenant estate. The goal: attribute every dollar back to the right tenant, keep it fresh as accounts move, and do it today, across historical data - without waiting on a backfill.

The challenge

Three facts about this setup drive the entire design.

  • Management-account CUR sees everything. The Cost and Usage Report (CUR 2.0) configured on the management account provides full visibility across every linked account in the Org, regardless of OU structure. OUs are governance constructs - they do not fragment billing data.
  • CUR has no native OU column. There is no ou_id field anywhere in CUR's ~125 columns. Segmentation by tenant/OU therefore has to happen at query time, by joining CUR to a mapping you maintain yourself.
  • The newest native lever is forward-looking. Account Tags for Cost Allocation - announced December 2025 - let you tag the account itself in AWS Organizations and have that tag flow into CUR 2.0. But like all cost-allocation tags, it applies from activation onward; it does not retroactively re-tag months you already billed. So it is the right long-term foundation and the wrong tool for the report your customer needs this quarter.

Without a deliberate design, tenant cost attribution becomes a rebuild rather than a query.

Three levers, in rough order of fit

In an OU-per-tenant model you have three ways to attribute spend. They are complementary, not competing.

  1. line_item_usage_account_id - free and immediate if each tenant maps to distinct account(s). No setup. This is the join key the pattern below uses.
  2. Account Tags for Cost Allocation - tag the account in Organizations (e.g. tenant=Tenant-A). The tag auto-applies to all usage in that account, including otherwise-untaggable costs like credits, refunds, and RI/Savings Plans discounts. This is the strongest long-term fit for OU-per-tenant - but forward-only.
  3. Cost Categories - rule-based grouping (by OU, account, or tag) into named tenant buckets, reusable across Cost Explorer, Budgets, and CUR.

The mapping-table pattern below is what gives you visibility today and over history, while account tags accumulate going forward. Use both: the pipeline for immediate and historical attribution, account tags as the durable foundation.

The solution: an OU mapping pipeline

The pattern is a small, self-refreshing pipeline, and the elegance is in how little machinery it needs. A Lambda pulls current OU membership from the Organizations API and writes a mapping CSV to S3. A lookup table over that CSV is joined to CUR at query time. That is the whole idea.

Architecture at a glance

Management Account  (CUR 2.0 configured here → S3 delivery)
├── OU: Tenant-A         → Accounts 111..., 222...
├── OU: Tenant-B         → Account 333...
└── OU: Shared-Services  → Account 444...

Analytics Account  ("Lighthouse")
├── Lambda:  pulls OU membership → writes mapping CSV to S3
├── Athena / Snowflake:  lookup table over mapping, joined to CUR
└── Reporting app:  queries for tenant-level cost

Signal flow

  1. Refresh - EventBridge triggers the Lambda on a daily/weekly schedule.
  2. Map - Lambda paginates the Organizations API, resolves each account's parent OU, writes an account→OU mapping CSV.
  3. Store - CSV lands in s3://your-analytics-bucket/mappings/.
  4. Query - Athena/Snowflake lookup table points at the CSV.
  5. Report - tenant cost = CUR JOIN mapping ON line_item_usage_account_id.

Why this holds up

  • No backfill dependency. Works today across all historical CUR data - where account tags cannot reach.
  • Self-healing. When an account moves between OUs, the next Lambda run picks up the new parent automatically. No manual edits.
  • Effectively zero cost. The Organizations API is free, the CSV is tiny, the join is trivial for any engine. Lambda + S3 + Athena - no servers, no clusters.
  • Graceful fallback. A COALESCE with resource tags keeps reporting continuous during migrations (shown below).

Implementation walkthrough

Prerequisites

  • An AWS Organization with an OU-per-tenant structure.
  • CUR 2.0 configured on the management (payer) account, delivering to S3.
  • An analytics account ("Lighthouse") with cross-account read access to the CUR bucket.
  • Python 3.9+ for the Lambda; AWS CLI v2 for setup.
  • Athena or Snowflake for querying (examples for both below).

Step 1 - Pull OU membership with Lambda

The Lambda paginates through every account in the Org, resolves each account's parent OU, and writes a flat account→OU mapping to S3. Accounts that sit directly under the root (not in an OU) are labelled Root so nothing falls through the cracks.

# account_ou_mapping.py
import boto3
import csv
import io

org_client = boto3.client('organizations')
s3_client = boto3.client('s3')

def lambda_handler(event, context):
    mapping = []
    paginator = org_client.get_paginator('list_accounts')

    for page in paginator.paginate():
        for account in page['Accounts']:
            account_id = account['Id']
            account_name = account['Name']

            # Resolve the account's parent OU
            parents = org_client.list_parents(ChildId=account_id)
            parent = parents['Parents'][0]

            if parent['Type'] == 'ORGANIZATIONAL_UNIT':
                ou_info = org_client.describe_organizational_unit(
                    OrganizationalUnitId=parent['Id']
                )
                ou_name = ou_info['OrganizationalUnit']['Name']
                ou_id = parent['Id']
            else:
                ou_name = 'Root'
                ou_id = 'ROOT'

            mapping.append({
                'account_id': account_id,
                'account_name': account_name,
                'ou_id': ou_id,
                'ou_name': ou_name,
            })

    # Write the mapping to S3
    output = io.StringIO()
    writer = csv.DictWriter(
        output,
        fieldnames=['account_id', 'account_name', 'ou_id', 'ou_name'],
    )
    writer.writeheader()
    writer.writerows(mapping)

    s3_client.put_object(
        Bucket='your-analytics-bucket',
        Key='mappings/account-ou-mapping.csv',
        Body=output.getvalue(),
    )

    return {'statusCode': 200, 'accounts_mapped': len(mapping)}

Note on nested OUs. list_parents returns the immediate parent. If your tenants sit several OU levels deep, walk list_parents up to the tenant-level OU rather than taking Parents[0] directly. For a flat OU-per-tenant estate, the immediate parent is the tenant OU, so the code above is sufficient.

Step 2 - Create the lookup table

Point a table at the mapping CSV in S3. The exact syntax depends on your query engine - here are both Athena and Snowflake, since many analytics stacks use one or the other.

Athena - external table

CREATE EXTERNAL TABLE account_ou_mapping (
    account_id   STRING,
    account_name STRING,
    ou_id        STRING,
    ou_name      STRING
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
LOCATION 's3://your-analytics-bucket/mappings/'
TBLPROPERTIES ('skip.header.line.count'='1');

Snowflake - stage, table, and load

-- Stage pointing at the same S3 path
CREATE STAGE ou_mapping_stage
    URL = 's3://your-analytics-bucket/mappings/'
    CREDENTIALS = (AWS_ROLE = 'arn:aws:iam::999999999999:role/snowflake-access');

CREATE TABLE account_ou_mapping (
    account_id   VARCHAR,
    account_name VARCHAR,
    ou_id        VARCHAR,
    ou_name      VARCHAR
);

COPY INTO account_ou_mapping FROM @ou_mapping_stage
    FILE_FORMAT = (TYPE = CSV SKIP_HEADER = 1);

Step 3 - Query tenant cost

With the lookup in place, tenant attribution is a single join on line_item_usage_account_id.

Column names are CUR 2.0 (Data Exports). CUR 2.0 uses snake_case line_item_* columns and stores the billing period as the timestamp column bill_billing_period_start_date. If you are still on Legacy CUR, the period column is billing_period and several product fields are flat (product_instance_type) rather than living in the product struct. Match the queries to whichever export you actually have.

Tenant cost by service

SELECT
    m.ou_name                     AS tenant,
    cur.line_item_product_code    AS service,
    SUM(cur.line_item_unblended_cost) AS cost
FROM cur_table cur
JOIN account_ou_mapping m
    ON cur.line_item_usage_account_id = m.account_id
WHERE cur.bill_billing_period_start_date = TIMESTAMP '2026-06-01 00:00:00'
GROUP BY 1, 2
ORDER BY 3 DESC;

Resource-level detail for one tenant - useful when a tenant asks "what exactly am I paying for?" (requires INCLUDE_RESOURCES on the export, which adds line_item_resource_id):

SELECT
    m.ou_name                  AS tenant,
    cur.line_item_resource_id,
    cur.line_item_product_code AS service,
    cur.product['instance_type'] AS instance_type,
    SUM(cur.line_item_unblended_cost) AS cost
FROM cur_table cur
JOIN account_ou_mapping m
    ON cur.line_item_usage_account_id = m.account_id
WHERE m.ou_name = 'Tenant-A'
    AND cur.bill_billing_period_start_date = TIMESTAMP '2026-06-01 00:00:00'
    AND cur.line_item_unblended_cost > 0
GROUP BY 1, 2, 3, 4
ORDER BY 5 DESC
LIMIT 50;

Worth testing against your own export. In CUR 2.0, product attributes live in a product map/struct - Athena reads them as product['instance_type'], and some engines expose it as product.instance_type. The exact accessor depends on how your table was created (Glue struct vs. string map). Confirm the shape on your own export before you rely on it; I have seen both.

Keeping it fresh - and catching the failure before a person does

A mapping table is only useful if it reflects reality, and the way this pattern fails is quiet. It does not error. It keeps running, keeps posting to the dashboard, and starts silently misattributing real spend the moment an account moves to an OU your mapping hasn't caught up with.

Here is what that looks like. Month 1, mapping current, report clean:

Data Platform    $84,210
ML Training      $61,900
Production      $203,450

Month 4 - two accounts were created for a project launched in month 2 and moved under new OUs, but the mapping ran before that and nobody re-checked:

Data Platform            $84,210
ML Training              $61,900
Production              $203,450
789012345678 (unmapped)  $19,300
890123456789 (unmapped)  $27,650

The report is accurate and useless at the exact moment it matters most - $46,950 of real spend, on real accounts, under raw IDs nobody in the meeting recognizes, and if that new project is the fastest-growing line in the business it is the one line that shows up unattributed.

Three habits keep the mapping honest:

  • Schedule the refresh. An EventBridge rule triggers the Lambda daily or weekly - your call, based on how often accounts actually move.
  • Let account moves self-heal. When an account changes OU, the next run picks up the new parent automatically. No manual edits.
  • Add a staleness check, and surface it in the report itself. Compare the distinct account IDs in CUR against the mapping. Any account present in CUR but missing from the mapping is unmatched spend - flag it rather than dropping it:
-- Unmatched spend: accounts billing in CUR with no mapping row
SELECT
    cur.line_item_usage_account_id AS unmapped_account,
    SUM(cur.line_item_unblended_cost) AS cost
FROM cur_table cur
LEFT JOIN account_ou_mapping m
    ON cur.line_item_usage_account_id = m.account_id
WHERE m.account_id IS NULL
    AND cur.bill_billing_period_start_date = TIMESTAMP '2026-06-01 00:00:00'
GROUP BY 1
ORDER BY 2 DESC;

Append that result to the same artifact people already read, and the drift becomes visible on the day it happens - not three months later when someone asks why the numbers don't reconcile:

Data completeness note
2 accounts are billing this period with no OU mapping:
789012345678, 890123456789 (combined $46,950). Add them to the
account→OU mapping to attribute this spend correctly.

Fallback: tagging during migration

Real estates are rarely static. If accounts are mid-migration between environments, your existing resource tags still work as a backup identifier. A COALESCE keeps reporting continuous - prefer the authoritative OU mapping, and fall back to the tag only where the mapping has a gap:

COALESCE(m.ou_name, cur.resource_tags['user_tenant']) AS tenant

(On Legacy CUR the same field is the flat column resource_tags_user_tenant.)

Security considerations

  • Least privilege. The Lambda needs only organizations:ListAccounts, organizations:ListParents, and organizations:DescribeOrganizationalUnit. Grant them via a scoped IAM role.
  • Protect the mapping. The CSV contains account IDs and OU names - store it in a private S3 bucket with server-side encryption (SSE-S3 or SSE-KMS).
  • Scope CUR access. Cross-account CUR reads should use a dedicated read-only IAM role scoped to the CUR prefix.
  • Audit. Enable CloudTrail on the Organizations API calls.

Cleanup

To remove everything created in this walkthrough:

  1. Delete the EventBridge rule triggering the Lambda.
  2. Delete the Lambda function and its IAM role.
  3. Remove the mapping CSV (or the entire mappings/ prefix) from S3.
  4. Drop the Athena external table, or the Snowflake table and stage.

Closing thoughts

What makes this pattern satisfying is how little it costs to run and how gracefully it degrades. The Organizations API is free, the mapping CSV is tiny, and the join is trivial for any query engine - yet it delivers accurate, self-refreshing, tenant-level cost visibility across an entire Org, today, over historical data, without waiting on a backfill.

If you are advising a customer who is still consolidating accounts, the highest-leverage conversation is about the segmentation model, and the message is the one from the top of this post: Account Tags at the account level is the strongest long-term foundation; the OU mapping pipeline is what gives them visibility in the meantime. Get that decision right early and tenant chargeback becomes a configuration detail rather than a project.

Questions worth asking before you build

  • Will each tenant be a single account, or multiple accounts under its OU?
  • Does the reporting app read CUR directly from S3/Athena, or via an intermediate export?
  • Do untaggable costs (credits, refunds, RI/SP discounts) need to be attributed per tenant? (Account tags win here.)
  • Do any tenants share resources? (Shared-cost splitting needs explicit allocation rules.)

Further reading

  • Simplify Departmental Cost Allocation with AWS Organizations and Lambda
  • Cost Reporting Based on AWS Organizations Account ID Tags
  • CUR 2.0 (Data Exports) table dictionary
  • Using Data Exports with AWS Organizations
  • Using Account Tags for Cost Allocation

About the authors

Atmankumar Vaghamshi is a Technical Account Manager at Amazon Web Services, specializing in cost optimization and multi-tenant architecture patterns for enterprise customers.

Dinesh Ginne is a Technical Account Manager at Amazon Web Services, helping enterprise customers with AWS cost management, multi-account governance, and FinOps.