SYS_PORTFOLIO_V1.0

"Behind You, a Syntax Error..."

?
Open this help
H / Home
Home
J
Journal
P
Projects
A
About
M
Toggle the navigation menu
← / →
Move between focused menu links
Ctrl + ← / →
Previous or next journal entry
Esc
Close this help or the navigation menu
───[ JOURNAL_ENTRY ]─── BACK_TO_ARCHIVE

AWS Cost Allocation Tags: CDK, Pipelines, and the Backfill You Still Need

───[ DM_READS ]───

Tags are not decoration—they are how finance sees your architecture. CDK and pipelines can stamp them; backfill still haunts legacy resources. You document the tagging covenant and the deploy hooks that enforce it.

Miss this quest and FinOps plays detective with spreadsheets—bad for everyone.

───[ ON_THIS_PAGE ]───

AWS cost allocation tags are easy to describe and hard to keep consistent. You add Application and Environment in CDK. Finance activates them in Billing. Cost Explorer finally groups spend the way architects draw boxes on a whiteboard.

Then someone deploys a Lambda from an old template. A sandbox script creates a queue without Workload. Your Resource Group filter requires Workload. Inventory shows zero resources. Everyone concludes FinOps is broken.

Part 1 covered the observability stack—dashboard, budgets, inventory. This post is part 2: how tags actually land on resources when you mix CDK, CI pipelines, and manual sandbox scripts on the same platform.

AWS cost allocation tags — CDK create-time vs ops backfill

In Brief

Tags are a contract between IaC, ops scripts, and Billing—not a one-time CDK exercise.

  • Propagate tags from environment config through Tags.of(stack) so every new resource inherits the same keys.
  • Treat pipeline deploys as the source of truth for shared environments; treat shell backfill as hygiene for drift and sandbox experiments.
  • Activate tags in the billing console only after resources carry values—not the other way around.
  • Do not tighten Resource Group queries until coverage is real.

Two Paths, One Tag Vocabulary

Resources get tags at creation—or they do not. Later, Cost Explorer cannot invent them.

  PATH A — create time                    PATH B — backfill
  --------------------                    -----------------
  env config (tags map)                   query existing ARNs
       │                                       │
       ▼                                       ▼
  CDK Tags.of(this).add(k, v)              tag-resources API
       │                                       │
       ▼                                       ▼
  cdk deploy (pipeline or local)            retry missing Workload/Region
       │                                       │
       └──────────────┬────────────────────────┘
                      ▼
           Billing → activate cost allocation tags
                      ▼
           Budgets + Cost Explorer filters

Same keys on both paths. Different spelling on one Lambda—and Finance opens an “untagged” bucket that dwarfs your product.

CDK: Tags Belong in the Stack Constructor

The pattern that scales: read tags from per-environment config, apply at stack scope once.

const envName = config.environment; // sandbox | prod
cdk.Tags.of(this).add("Environment", envName);
for (const [key, value] of Object.entries(config.tags)) {
  cdk.Tags.of(this).add(key, value);
}

Typical config.tags entries for a multi-stack platform:

Key Example Notes
Application my-research-platform Matches FinOps budget filter
Workload ris Short prefix for automation
Project ris Optional; align with repo name
CostCenter engineering Finance chargeback
Owner platform-team Escalation

Foundation, services, and application stacks each call the same pattern. Duplicating tag lines inside every construct is how Environment becomes sandbox in one stack and Sandbox in another.

Some resources resist in-place tag updates on deploy (load balancers are a common case). CDK may exclude resource types from tag updates on mature stacks. That is not an excuse to skip tags on new resources—it is a reason the backfill script still exists.

Study tip: One YAML/TS config file per environment. Tags live there. Stacks only read.

Pipelines vs Sandbox Scripts

Discipline differs by risk.

Environment Who deploys Tag expectation
Production CI only (e.g. Bitbucket → CodeBuild → cdk deploy) Tags from CDK on every release; no ad-hoc console creates
Sandbox CDK pipeline or imperative scripts (VPC wizard, FinOps apply) CDK-tagged stacks plus script-tagged stray resources

Shared accounts die from “just this once” sandbox deploys without tags. Your AWS cost allocation tags story must include: prod is pipeline-governed; sandbox is explicitly messy and gets a backfill pass after experiments.

FinOps automation (finops-dashboard.sh apply) is not a replacement for CDK. It is the mop: Resource Group, dashboard, budget, and tag-resources for anything that predates the standard or was created outside CDK.

What the Backfill Pass Actually Does

A practical backfill queries by signals you already have:

  • Everything with Application=<your-app> but missing Workload or Region
  • Resources matching name patterns ({workload}-{environment}-*, state machine prefixes, known Lambda names)
  • Older task definitions and stacks deployed before the tag map was centralized

Log failures. KMS keys pending deletion often cannot be tagged. Some CloudFormation-only ARNs reject API calls. A non-zero failure count is honest; pretending 100% coverage is not.

Re-run after:

  • Cloning sandbox from a template account
  • Adding a new ingestion Lambda outside the main stack
  • Any “quick fix” deploy during an incident

The Workload Filter Trap

Resource Groups can require Workload in addition to Application and Environment. That is correct eventually. It is catastrophic early.

Empty inventory makes the team distrust the whole FinOps layer. Keep the group permissive until backfill metrics say you are done. Then flip FINOPS_REQUIRE_WORKLOAD_TAG=true (or equivalent) in automation.

Activate in Billing—Once

Creating tags on resources is step one. Activating them for cost allocation is step two—in the management account Billing preferences. Until activation, budgets and Cost Explorer groups look empty or partial.

Order of operations:

  1. Tag resources (CDK + backfill)
  2. Activate keys in Billing
  3. Wait for propagation (often 24 hours for historical views)
  4. Create budgets filtered on Application + Environment
  5. Open the FinOps dashboard and verify splits

Anti-Patterns

  • Tag sprawl — Fifteen keys in config; Finance uses two.
  • Per-developer sandbox tags — Environment=jsmith breaks chargeback.
  • Backfill once, never again — Every new Lambda is a regression test.
  • Strict Resource Group on day one — Zero rows, zero confidence.
  • Assuming CDK fixed last month’s Lambdas — It did not.

Closing

AWS cost allocation tags need IaC at create time and ops discipline after the fact. CDK gives you the default; pipelines guard production; backfill heals sandbox and drift.

Part 3 goes signal-by-signal: Bedrock tokens, SQS age, and when Aurora is a red herring.


Further reading


Series: AWS FinOps on Complex Workloads

Part Topic
1 — AWS FinOps overview Dashboard, budgets, automation
2 (this post) CDK, pipelines, backfill
3 — Bedrock & pipeline signals Reading the dashboard

Feel free to share your thoughts by emailing me or reaching out on social media.

Licensed under CC BY-NC-ND 4.0. You may share with attribution under the license terms.