AWS Builder Center
Monitoring Kiro across an AWS Organization with Terraform and QuickSight

Monitoring Kiro across an AWS Organization with Terraform and QuickSight

One QuickSight dashboard for every Kiro account, with each account's data kept in that account. Terraform module, tests, cost numbers and the S3 LIST bill we learned to avoid.

AI Engineer at Renova Cloud - AWS Premiere Partner - 8x AWS Certified - First Cloud AI Journey

Monitoring Kiro across an AWS Organization with Terraform: one dashboard, each account keeps its own data

When a company rolls out Kiro to several AWS accounts, administrators soon ask three questions. Who is actually using it? Which paid seats sit idle? How much does the monitoring itself cost? The Kiro console answers these one account at a time. This article builds one Amazon QuickSight dashboard for every Kiro account in an organization. Each account's data stays in that account, and the dashboard account only reads it.
You will deploy:
  • a Terraform module that builds the data side of one Kiro account: report bucket, backup, normalizer Lambda, data lake and Glue tables;
  • one Terraform root per account, entered through  OrganizationAccountAccessRole ;
  • a CUR 2.0 export with Kiro line items only, which is how you find idle licences.
Status at the time of writing. The management account has run the single-account version of this pipeline since 2 November 2026, and its dashboard matches the raw CSV exactly. The per-account Terraform module passes 11 offline tests but has not been applied to a member account yet. Two points are still open and listed at the end: cross-account catalog reads from QuickSight, and CUR delivery to another account's bucket.
All code is in the GitHub repository linked at the end of the article. The snippets below are copied from it, not rewritten.

Architecture

Kiro Monitoring Enterprise Architecture

The numbers follow the diagram.
Management account (payer, IAM Identity Center):
  1. Users sign in to Kiro with the organization's IAM Identity Center. Their subscriptions are billed to this account.
  1. Every day at about 02:00 UTC, Kiro writes the User Activity Report (CSV) to an S3 bucket in the same account, in the Region of the Kiro profile (us-east-1).
  1. Amazon EventBridge runs the normalizer Lambda at 03:15 UTC, in the dashboard Region (ap-southeast-1).
  1. The normalizer reads the new report files. It reads each column by its header name, because Kiro adds a  <model>_messages  column whenever a new model launches.
  1. The normalizer writes one row per user and day (facts) and one row per user, day and model (models) to the data lake bucket. Two Glue tables expose them.
  1. The identity-map Lambda reads users from Identity Center, because the report carries only a user ID.
  1. It writes the user ID to name and email table to its own bucket. Steps 6 and 7 run only here, because the user directory belongs to the whole organization.
  1. AWS Data Exports delivers a CUR 2.0 export with Kiro line items only. This is the only source that lists seats with no activity.
Member accounts, one copy each, nothing shared:
  1. Users work in Kiro through that account's own Kiro profile.
  1. Kiro writes that account's report to that account's own bucket.
  1. That account's EventBridge rule starts that account's normalizer.
  1. The normalizer reads the account's report.
  1. It writes to the account's own data lake. The account pays for what runs in it.
Dashboard account (read only):
  1. Amazon Athena reads the management account's Glue tables and S3 objects through a resource policy that grants read actions only.
  1. The same for each member account.
  1. SPICE imports from Athena once a day, over a rolling 3-month window.
  1. The dashboard reads SPICE and filters by account.
  1. Administrators open the dashboard. Opening it runs no Athena query, so viewing costs nothing extra.

Design decisions

  • Pull, not push. Kiro writes the report only to a bucket in the account where users are subscribed. So each account keeps its bucket, and the dashboard account reads. A single shared bucket for the organization is not an option.
  • One data lake per account, not one central lake. A central lake would put every account's data, and its storage and request costs, into the dashboard account. Per-account lakes keep data and cost where they belong and let you remove one account without touching the others.
  • Data lake in the dashboard Region. Athena reads another account's Glue catalog only in the same Region ( Athena documentation ). The report stays in us-east-1 where Kiro writes it, and the normalizer reads it across Regions inside the same account.
  • Daily refresh, not every 15 minutes. Kiro publishes once a day. A 15-minute refresh re-reads the same data 96 times a day and multiplies S3 request costs. Section "What broke" has the numbers.
  • SPICE, not Direct Query. With SPICE, the number of viewers and page loads does not change the Athena bill.
  • Identity map and CUR only in the management account. The Identity Center user store and the bill cover the whole organization, so one copy is enough.

Prerequisites

  • Terraform 1.6 or later (tested with 1.13.4), AWS provider 6.0 or later (tested with 6.70.0), archive provider 2.4 or later (tested with 2.8.1).
  • Python 3 and Bash (Git Bash on Windows) for the dashboard deploy script.
  • A CLI profile in the management (payer) account that can assume  OrganizationAccountAccessRole  in member accounts.
  • Amazon QuickSight Enterprise edition in the dashboard account.
  • A Kiro profile in each account, connected to the organization's Identity Center.

Step 1: Clone and run the tests

git clone https://github.com/nghidanh2005/kiro-enterprise-monitoring.git
cd kiro-enterprise-monitoring/infra/tests
terraform init -backend=false
terraform test -filter=tests/data-lake.tftest.hcl
The tests plan the module against mocked AWS providers, so they need no credentials and create nothing. Expected output:
tests/data-lake.tftest.hcl... in progress
run "report_policy_lets_only_this_accounts_kiro_write_under_the_prefix"... pass
run "lake_has_no_cross_account_access_by_default"... pass
run "consumers_get_read_only_and_nothing_else"... pass
run "glue_resource_policy_can_be_left_alone"... pass
run "consumer_must_be_a_role"... pass
run "normalizer_role_is_scoped_to_its_prefixes"... pass
run "boundary_goes_on_both_roles"... pass
run "projection_window_is_rolling_and_short"... pass
run "projection_rejects_a_future_end_date"... pass
run "backup_is_replicated_and_cannot_be_emptied"... pass
run "backup_can_be_switched_off"... pass
tests/data-lake.tftest.hcl... tearing down
tests/data-lake.tftest.hcl... pass

Success! 11 passed, 0 failed.
On Windows, write the filter with a backslash:  -filter='tests\data-lake.tftest.hcl' . With a forward slash, Terraform reports  0 passed, 0 failed  and runs nothing.
The tests check policies, names and guards. They cannot prove that AWS accepts them; the first real  terraform plan  does that.

Step 2: The root for one account

 infra/roots/member-account/main.tf  builds one account. It has two AWS providers, because the report bucket lives in the Kiro Region and everything else in the dashboard Region. Both enter the account through  OrganizationAccountAccessRole , and both refuse to run anywhere else.
locals {
role_arn = var.assume_role_name == null ? null : "arn:aws:iam::${var.account_id}:role/${var.assume_role_name}"
}

provider "aws" {
region = var.lake_region
profile = var.profile
allowed_account_ids = [var.account_id]
default_tags {
tags = { Project = "kiro-monitoring", ManagedBy = "terraform" }
}
dynamic "assume_role" {
for_each = local.role_arn == null ? [] : [local.role_arn]
content {
role_arn = assume_role.value
session_name = "kiro-mon-terraform"
}
}
}

provider "aws" {
alias = "report"
region = var.report_region
profile = var.profile
allowed_account_ids = [var.account_id]
default_tags {
tags = { Project = "kiro-monitoring", ManagedBy = "terraform" }
}
dynamic "assume_role" {
for_each = local.role_arn == null ? [] : [local.role_arn]
content {
role_arn = assume_role.value
session_name = "kiro-mon-terraform"
}
}
}

module "data_lake" {
source = "../../customer/data-lake"
providers = {
aws = aws
aws.report = aws.report
}
slug = var.slug
consumer_role_arns = var.consumer_role_arns
permissions_boundary_arn = var.permissions_boundary_arn
reserved_concurrency = var.reserved_concurrency
enable_backup = var.enable_backup
manage_glue_resource_policy = var.manage_glue_resource_policy
}
 lake_region  defaults to  ap-southeast-1  and  report_region  to  us-east-1 . Change both to match your dashboard Region and your Kiro profile Region.
Copy  terraform.tfvars.example  to a file outside git, one per account:
account_id = "111122223333"
slug = "kiro01"
profile = "payer-profile"

# Leave empty for the first apply; fill in the dashboard account's QuickSight
# role when the pilot is ready to read.
consumer_role_arns = []

# Only when the account has a boundary policy (patch P5):
# permissions_boundary_arn = "arn:aws:iam::111122223333:policy/your-boundary"

# The management account itself uses its own profile instead of a role:
# assume_role_name = null

Step 3: What the module builds

The module is  infra/customer/data-lake/main.tf . These are the parts that matter most.

Only this account's Kiro may write the report

The Kiro service principal may put objects only under the prefix, only from this account's  codewhisperer  ARN. The  aws:SourceAccount  and  aws:SourceArn  conditions stop another account's Kiro from writing into the bucket (the confused-deputy problem). A deny on  s3:DeleteBucket  protects the only copy of the history.
report_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "KiroUserReportWrite"
Effect = "Allow"
Principal = { Service = "q.amazonaws.com" }
Action = "s3:PutObject"
Resource = "${local.report_arn}/${var.report_prefix}*"
Condition = {
StringEquals = { "aws:SourceAccount" = local.account_id }
ArnLike = { "aws:SourceArn" = "arn:${local.p}:codewhisperer:${local.report_region}:${local.account_id}:*" }
}
},
local.tls_only,
{
Sid = "DenyReportBucketDelete"
Effect = "Deny"
Principal = "*"
Action = "s3:DeleteBucket"
Resource = local.report_arn
},
]
})
The bucket also has versioning, SSE-S3, Block Public Access,  BucketOwnerEnforced  and  lifecycle { prevent_destroy = true } .

A backup that deletes do not reach

The raw report is the only copy of the history. In our account, no report arrived for days before we turned it on. Replication copies  kiro/  to a backup bucket, and delete markers are not replicated:
resource "aws_s3_bucket_replication_configuration" "report" {
count = var.enable_backup ? 1 : 0
provider = aws.report
bucket = aws_s3_bucket.report.id
role = aws_iam_role.replication[0].arn

rule {
id = "backup-report"
status = "Enabled"
priority = 1
filter {
prefix = var.report_prefix
}
delete_marker_replication {
status = "Disabled"
}
destination {
bucket = aws_s3_bucket.backup[0].arn
}
}

depends_on = [aws_s3_bucket_versioning.report, aws_s3_bucket_versioning.backup, aws_iam_role_policy.replication]
}
The backup bucket policy denies  s3:DeleteObject ,  s3:DeleteObjectVersion  and  s3:DeleteBucket  for everyone. Replication does not copy objects that existed before the rule; Step 5 covers that.

The normalizer, scoped to two prefixes

The Lambda runs on arm64 with 256 MB of memory. Its role reads only this account's  user_report/  prefix and writes only  normalized/ :
resource "aws_lambda_function" "normalizer" {
function_name = local.function_name
role = aws_iam_role.normalizer.arn
runtime = var.lambda_runtime
architectures = ["arm64"]
handler = "normalize_report_lambda.handler"
filename = data.archive_file.normalizer.output_path
source_code_hash = data.archive_file.normalizer.output_base64sha256
timeout = 900
memory_size = 256
reserved_concurrent_executions = var.reserved_concurrency == null ? -1 : var.reserved_concurrency
tags = local.tags

environment {
variables = {
RAW_BUCKET = local.report_bucket
RAW_PREFIX = local.raw_prefix
OUT_BUCKET = local.lake_bucket
OUT_PREFIX = local.out_prefix
}
}

depends_on = [aws_cloudwatch_log_group.normalizer, aws_iam_role_policy.normalizer]
}

resource "aws_cloudwatch_event_rule" "daily" {
name = "${local.function_name}-daily"
schedule_expression = var.schedule
state = "ENABLED"
tags = local.tags
}
 var.schedule  defaults to  cron(15 3 * * ? *) , 75 minutes after Kiro writes the report. The Lambda code is the vendored sample's  normalize_report_lambda.py , zipped by the  archive  provider.
 reserved_concurrency  defaults to no reservation. New accounts often have a Lambda concurrency limit of 10, and AWS refuses any reservation that leaves fewer than 10 unreserved.

Glue tables with a rolling partition window

This is the setting that decides the S3 request bill:
raw_table_params = {
"EXTERNAL" = "TRUE"
"skip.header.line.count" = "1"
"projection.enabled" = "true"
"projection.export_date.type" = "date"
"projection.export_date.format" = "yyyy-MM-dd"
"projection.export_date.range" = var.projection_range
"projection.export_date.interval" = "1"
"projection.export_date.interval.unit" = "DAYS"
}
With partition projection, Athena lists one S3 prefix for every day in the range, whether or not the prefix holds data. The variable refuses ranges that would list prefixes that cannot exist:
variable "projection_range" {
description = "Days the raw tables project. Every read lists one S3 prefix per day in this window, so keep it rolling and short (never a fixed old start date)."
type = string
default = "NOW-3MONTHS,NOW"
validation {
condition = can(regex("^NOW-[0-9]{1,2}(MONTHS|WEEKS)(,NOW)$", var.projection_range)) || can(regex("^[0-9]{4}-[0-9]{2}-[0-9]{2},NOW$", var.projection_range))
error_message = "projection_range must be NOW-<n>MONTHS,NOW or yyyy-MM-dd,NOW. A future end such as NOW+1YEARS is refused: it lists prefixes that cannot exist yet."
}
}
A test pins this, so the upstream range cannot come back unnoticed:
run "projection_rejects_a_future_end_date" {
command = plan
module {
source = "../customer/data-lake"
}
providers = {
aws = aws
aws.report = aws.report
}
variables {
slug = "kiro01"
projection_range = "2020-01-01,NOW+1YEARS"
}
expect_failures = [var.projection_range]
}

Read-only grants for the dashboard account

 consumer_role_arns  is empty by default, so a first apply gives the dashboard account nothing. When you fill it in, the lake bucket policy adds  s3:GetObject  and  s3:ListBucket  on  normalized/  only, and the Glue resource policy adds read actions on this database only:
glue_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Sid = "ConsumerReadCatalog"
Effect = "Allow"
Principal = { AWS = var.consumer_role_arns }
Action = [
"glue:GetDatabase", "glue:GetDatabases", "glue:GetTable", "glue:GetTables",
"glue:GetPartition", "glue:GetPartitions", "glue:BatchGetPartition",
]
Resource = [
"arn:${local.p}:glue:${local.lake_region}:${local.account_id}:catalog",
"arn:${local.p}:glue:${local.lake_region}:${local.account_id}:database/${local.database}",
"arn:${local.p}:glue:${local.lake_region}:${local.account_id}:table/${local.database}/*",
]
}]
})
An account and Region has one Glue resource policy, and this resource replaces it. Check first with  aws glue get-resource-policy . If the account already has a policy, set  manage_glue_resource_policy = false  and merge the statement by hand.

Step 4: Plan, apply and turn on the report

Run these read-only checks first:
aws sts get-caller-identity --profile payer-profile
aws lakeformation get-data-lake-settings --region ap-southeast-1 # through the assumed role
aws glue get-resource-policy --region ap-southeast-1 # through the assumed role
If Lake Formation governs the catalog, the cross-account read needs extra grants. Then plan:
cd infra/roots/member-account
terraform init -backend-config="path=../../../customers/<slug>/state-<account-slug>/terraform.tfstate"
terraform plan -var-file=../../../customers/<slug>/<account-slug>.tfvars -out=plan.tfplan
terraform apply plan.tfplan
The plan must show only creates and no destroy. Stop on anything else. Keep one state per account.
In that account's Kiro console, turn on the user activity report and enter the root output  report_s3_uri_for_kiro_console . The console only accepts a URI that ends with the prefix, for example  s3://kiro-user-report-111122223333/kiro/ .
Then measure, do not assume:
  • an object appears under  kiro/AWSLogs/<account>/KiroLogs/  within a minute;
  • after the next 02:00 UTC report,  python tools/verify_backup.py --source kiro-user-report-<acct> --backup kiro-mon-backup-<acct> --profile <p>  exits 0;
  • after 03:15 UTC, the normalizer log shows  files_failed: 0 , and the row count in  normalized/facts/  equals the row count of the CSV. Count both with two different tools.

Step 5: Adopting the management account's existing bucket

If an account already has a report bucket, it holds the only copy of its history. Terraform must adopt it, never create or replace it. Back it up and prove the backup first:
aws s3 sync s3://kiro-user-report-<acct>/kiro/ s3://kiro-mon-backup-<acct>/kiro/ --profile <p> --region <report-region>
python tools/verify_backup.py --source kiro-user-report-<acct> --backup kiro-mon-backup-<acct> --profile <p>
Then import the bucket and its settings, one resource at a time:
terraform import module.data_lake.aws_s3_bucket.report kiro-user-report-<acct>
terraform import module.data_lake.aws_s3_bucket_versioning.report kiro-user-report-<acct>
terraform import module.data_lake.aws_s3_bucket_server_side_encryption_configuration.report kiro-user-report-<acct>
terraform import module.data_lake.aws_s3_bucket_public_access_block.report kiro-user-report-<acct>
terraform import module.data_lake.aws_s3_bucket_ownership_controls.report kiro-user-report-<acct>
terraform import module.data_lake.aws_s3_bucket_policy.report kiro-user-report-<acct>
After the imports, the plan for the report bucket may only create the lifecycle and replication rules, update tags and change the bucket policy. Nothing may be destroyed.

Step 6: The dashboard account

The dashboard comes from the AWS sample, deployed with its own  deploy.sh  (CloudFormation plus Python). We vendored it and added patches;  vendor/PATCHES.md  lists each one.
cd vendor/sample-kiro-user-analytics-quicksight-dashboard
export AWS_REGION=ap-southeast-1
export STACK_PREFIX=kiro-acme
export KIRO_LOGS_BUCKET=kiro-user-report-111122223333
export KIRO_LOGS_PREFIX=kiro/
export QS_PRINCIPAL_ARN=arn:aws:quicksight:ap-southeast-1:444455556666:user/default/admin
export PROJECTION_START=NOW-3MONTHS
# export PERMISSIONS_BOUNDARY_ARN=arn:aws:iam::444455556666:policy/your-boundary
bash scripts/deploy.sh
Three patches matter here:
  • P5, permissions boundary. Our dashboard account requires a boundary on every new IAM role. Without it,  iam:CreateRole  fails with an explicit deny.  PERMISSIONS_BOUNDARY_ARN  adds the boundary to the sample's roles.
  • P6, no default projection start. Upstream projects  2020-01-01,NOW+1YEARS . Now  deploy.sh  stops before any AWS call if  PROJECTION_START  is missing. It accepts a date or a rolling window such as  NOW-3MONTHS .
  • P7, a scoped Athena policy.  scripts/grant_quicksight_athena.py  writes an inline policy,  <STACK_PREFIX>-QuickSightAthenaAccess , on the QuickSight service role. It allows Athena only on this deployment's workgroup and Glue reads only on its database:
{
"Sid": "AthenaOnWorkgroup",
"Effect": "Allow",
"Action": [
"athena:StartQueryExecution", "athena:StopQueryExecution",
"athena:GetQueryExecution", "athena:BatchGetQueryExecution",
"athena:GetQueryResults", "athena:GetQueryResultsStream",
"athena:GetWorkGroup",
],
"Resource": f"{athena}:workgroup/{workgroup}",
},

Step 7: CUR 2.0 for idle licences

The activity report has one row per user and day of activity. It does not list subscriptions, so a seat that nobody uses never appears in it. To see seats that are paid for but unused, you join the report with the bill.  infra/customer/cur-export  creates a Data Exports export in the payer account, filtered to Kiro:
locals {
# Column list copied from awslabs/cid-data-collection-framework (Apache-2.0),
# data-exports/deploy/data-exports-aggregation.yaml line 243 (DefaultQuery), commit c747c93.
cid_columns = file("${path.module}/cid_cur2_columns.txt")
where = join(" OR ", [for c in var.product_codes : "line_item_product_code = '${c}'"])
query = "SELECT ${trimspace(local.cid_columns)} FROM COST_AND_USAGE_REPORT WHERE ${local.where}"
bucket = "${var.resource_prefix}-${var.observability_account_id}-data-exports"
prefix = "cur2/${data.aws_caller_identity.current.account_id}"
}
The column list and bucket naming match the Cloud Intelligence Dashboards (CID) data exports, so CID's own views can read it unchanged. A precondition refuses a column list without  line_item_resource_id , the column licences are counted from. The first useful idle count needs one full closed month of both CUR and activity data.

What broke, and what it taught us

The S3 LIST bill from partition projection. On a similar QuickSight usage dashboard we deployed earlier, the default projection scanned every day from 2024 to 2030: about 2,600 S3 LIST calls per refresh. That dashboard refreshed every 15 minutes, had 5 dashboards and ran in 2 stacks, which comes to about 2.5 million LIST calls a day. The Kiro sample had the same pattern with  2020-01-01,NOW+1YEARS : about 2,860 prefixes per table read, almost all empty, growing by 365 a year. A rolling  NOW-3MONTHS,NOW  window lists about 92.
A shared QuickSight role. Every QuickSight dashboard in an account uses the same service role,  aws-quicksight-service-role-v0 . Another project's  terraform destroy  detached the managed policy  AWSQuicksightAthenaAccess  from it, and the next SPICE refresh failed with  athena:StartQueryExecution not authorized . CloudTrail showed which run did it. Patch P7 gives each deployment its own scoped inline policy, so another project's Terraform can no longer break this dashboard.
Do not attach shared policies from a module. The same incident applies to your own code: a module that attaches a policy to a shared role removes it on  destroy . Our fix in the other project created that attachment only when the module also created the role.
Small limits that cost a deploy. New accounts can have a Lambda concurrency limit of 10. The Glue resource policy replaces any existing one. S3 replication does not copy objects that existed before the rule. Each of these is handled by a variable or a documented step above.

Cost

Measured on the management account's running pipeline (single-account version), the monitoring itself costs about $0.40 a month per account, not counting QuickSight licences:
  • S3 LIST from the projected window: about $0.35;
  • Athena: 40 queries on a typical day, about $0.0009 that day;
  • Lambda, CloudWatch Logs, Glue and EventBridge: below the free tier;
  • SPICE: 87.6 KB across 8 datasets.
The per-account cost lands in that account. The dashboard account pays for Athena queries and QuickSight only.

Tradeoffs and when not to use this

  • One account only? Use the AWS sample as it is. The per-account split adds a state file and a role per account, and only pays off with several Kiro accounts.
  • Athena bills the account that runs the query. You cannot move query cost to the member accounts. It is small, but it is not zero.
  • Lake Formation. If an account's catalog is governed by Lake Formation, the cross-account read needs Lake Formation grants in addition to the Glue resource policy. The module does not create them.
  • History starts the day you turn on the report. We received no earlier days. CUR can back-fill the bill, but not activity.
  • A daily dashboard. Data is a day old by design. If you need same-day numbers, this is the wrong tool.

What is still open

  • QuickSight reading a member account's Glue catalog through Athena has not been tested end to end. The catalog registration in the dashboard account is the next patch.
  • Whether Data Exports can deliver CUR to a bucket in another account using the bucket policy alone. The API has no bucket-owner field, so the pilot measures it first.
  • Whether a member account's Kiro writes its report to its own bucket like the management account does. The pilot checks for the first object.

Code

The Terraform module, the per-account root, the tests, the patched sample and the runbook are on GitHub:  nghidanh2005/kiro-enterprise-monitoring . Start with  docs/MEMBER-ACCOUNTS.md  for the step-by-step pilot.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article