注:更新了Kiro在CUR中的数据解释、Athena自动分区、以及查询所用用户所有月份的方法。
一、背景
由于目前(2026-02-07)Kiro的控制台Dashboard暂时不能显示单个用户的Credit使用情况,因此建议通过计费系统进行查询。本文讲述如何使用Athena查询CUR V2获得Kiro用户的Credit使用情况。
1、Kiro计费模式
Kiro目前提供三个级别的订阅,分别是:
- Pro: 内含 1000 Credit;
- Pro+:内含 2000 Credit;
- Power:内含 10000 Credit;
以上,超出套餐内的使用量之后,额外消耗的Credit按照$0.04/credit计费。
官方对Credit的解释如下:https://kiro.dev/pricing/#what-is-a-credit
Credit(积分)是响应用户提示的工作单位。简单的提示可能消耗不到 1 个积分。
更复杂的提示,例如执行规格任务,通常会消耗超过 1 个积分。
此外,不同的模型以不同的速率消耗积分,使用Sonnet 4 执行提示比使用 Auto 执行消耗更多积分。
由于目前(2026-01)Kiro的控制台Dashboard暂时不能显示单个用户的Credit使用情况,因此建议通过AWS云的账单系统的CUR数据进行查询。
2、CUR V2介绍
AWS CUR V2(Cost and Usage Report 2.0) 是 AWS 在 2023 年 re:Invent 发布的新版成本和用量报告,为用户给出完整的账单计费原始数据并保存到S3存储桶中。CUR V2支持csv(gzip压缩)或者parquet格式,可以使用Athena服务的SQL语句进行查询。
CUR V2和原先的V1主要区别是,每个月份是一个独立的目录(或者叫Prefix前缀),而其中所有数据会被合并为单一的文件,每次新数据到来时候,都可以自动刷新、聚合、并压缩为parquet列格式。由此就不会产生海量的小尺寸碎文件了。这对于使用Athena查询CUR配置分区键、减少扫描文件范围、提升查询速度、降低查询成本都非常有好处。
以下是开启Parquet存储格式的CUV V2存储桶的目录结构示意。
.
└── cur-v2
├── data
│ ├── BILLING_PERIOD=2025-08
│ │ └── cur-v2-00001.snappy.parquet
│ ├── BILLING_PERIOD=2025-09
│ │ └── cur-v2-00001.snappy.parquet
│ ├── BILLING_PERIOD=2025-10
│ │ └── cur-v2-00001.snappy.parquet
│ ├── BILLING_PERIOD=2025-11
│ │ └── cur-v2-00001.snappy.parquet
│ ├── BILLING_PERIOD=2025-12
│ │ └── cur-v2-00001.snappy.parquet
│ ├── BILLING_PERIOD=2026-01
│ │ └── cur-v2-00001.snappy.parquet
│ └── BILLING_PERIOD=2026-02
│ └── cur-v2-00001.snappy.parquet
└── metadata
├── BILLING_PERIOD=2025-08
│ └── cur-v2-Manifest.json
├── BILLING_PERIOD=2025-09
│ └── cur-v2-Manifest.json
├── BILLING_PERIOD=2025-10
│ └── cur-v2-Manifest.json
├── BILLING_PERIOD=2025-11
│ └── cur-v2-Manifest.json
├── BILLING_PERIOD=2025-12
│ └── cur-v2-Manifest.json
├── BILLING_PERIOD=2026-01
│ └── cur-v2-Manifest.json
└── BILLING_PERIOD=2026-02
└── cur-v2-Manifest.json
二、创建CUR V2
1、创建S3存储桶
创建一个用于保存CUR数据的存储桶,放在美东1(us-east-1)区域。存储桶设置全默认即可。
2、开启CUR V2
进入AWS控制台,进入Billing and Cost Management服务,在左侧菜单下,找到菜单项Cost and Usage Analysis,再从中找到Data Exports,点击进去。
点击Create创建按钮,选择如下:
- 类型选择
Standard data export - 名字自行拟定
- Data table content settings选择
CUR 2.0 - Billing view设置不用修改
- Additional export content设置不用修改
- Time granularity选择为
daily或Hourly均可 - SQL statement默认已经选中了所有列,不用修改
- Data export delivery options的Compression type and file format选择
Parquet - Parquet - Data export storage settings位置输入上一步创建的S3存储桶和路径,建议在存储桶根目录下增加子目录(prefix),例如
s3://cur-v2-myaws/cur-export,有子目录便于未来创建Athena表格
其他设置无须修改,点击创建。
3、等待24-48小时生成第一批CUR数据
注意:
- CUR有较大延迟,通常在1天以上,创建CUR时候有个时间颗粒度选项,hourly或者daily,这表示CUR明细的颗粒度,但不意味着选hourly就是每小时推送CUR数据。CUR数据是按天推送的
- CUR只记录打开一刻起的数据。例如本月15日启用了CUR,那么17日左右开始生成15-16日的数据,15日之前的将不会提供CUR
三、使用Athena查询CUR数据获取Kiro使用量
在等待24-48小时后,CUR有了数据,继续创建表格做查询。
1、使用Athena创建表、并开启动态分区
进入Athena服务,在默认database下执行如下SQL创建表。注意替换以下SQL中的S3存储桶的路径’s3://cur-lxy-us-east-1/cur-v2/cur-v2/data/‘为实际的CUR保存目录下自动生成的data目录。你可以从S3存储桶服务界面去查看目录,直到发现最后一层data目录。此外还需要替换时间开始范围,例如本例从2025年8月开始到当下,则配置写为'2025-08,NOW'。
CREATE EXTERNAL TABLE `default`.`cur_v2data_projected` (
bill_bill_type string,
bill_billing_entity string,
bill_billing_period_end_date timestamp,
bill_billing_period_start_date timestamp,
bill_invoice_id string,
bill_invoicing_entity string,
bill_payer_account_id string,
bill_payer_account_name string,
cost_category map<string,string>,
discount map<string,double>,
discount_bundled_discount double,
discount_total_discount double,
identity_line_item_id string,
identity_time_interval string,
line_item_availability_zone string,
line_item_blended_cost double,
line_item_blended_rate string,
line_item_currency_code string,
line_item_legal_entity string,
line_item_line_item_description string,
line_item_line_item_type string,
line_item_net_unblended_cost double,
line_item_net_unblended_rate string,
line_item_normalization_factor double,
line_item_normalized_usage_amount double,
line_item_operation string,
line_item_product_code string,
line_item_resource_id string,
line_item_tax_type string,
line_item_unblended_cost double,
line_item_unblended_rate string,
line_item_usage_account_id string,
line_item_usage_account_name string,
line_item_usage_amount double,
line_item_usage_end_date timestamp,
line_item_usage_start_date timestamp,
line_item_usage_type string,
pricing_currency string,
pricing_lease_contract_length string,
pricing_offering_class string,
pricing_public_on_demand_cost double,
pricing_public_on_demand_rate string,
pricing_purchase_option string,
pricing_rate_code string,
pricing_rate_id string,
pricing_term string,
pricing_unit string,
product map<string,string>,
product_comment string,
product_fee_code string,
product_fee_description string,
product_from_location string,
product_from_location_type string,
product_from_region_code string,
product_instance_family string,
product_instance_type string,
product_instancesku string,
product_location string,
product_location_type string,
product_operation string,
product_pricing_unit string,
product_product_family string,
product_region_code string,
product_servicecode string,
product_sku string,
product_to_location string,
product_to_location_type string,
product_to_region_code string,
product_usagetype string,
reservation_amortized_upfront_cost_for_usage double,
reservation_amortized_upfront_fee_for_billing_period double,
reservation_availability_zone string,
reservation_effective_cost double,
reservation_end_time string,
reservation_modification_status string,
reservation_net_amortized_upfront_cost_for_usage double,
reservation_net_amortized_upfront_fee_for_billing_period double,
reservation_net_effective_cost double,
reservation_net_recurring_fee_for_usage double,
reservation_net_unused_amortized_upfront_fee_for_billing_period double,
reservation_net_unused_recurring_fee double,
reservation_net_upfront_value double,
reservation_normalized_units_per_reservation string,
reservation_number_of_reservations string,
reservation_recurring_fee_for_usage double,
reservation_reservation_a_r_n string,
reservation_start_time string,
reservation_subscription_id string,
reservation_total_reserved_normalized_units string,
reservation_total_reserved_units string,
reservation_units_per_reservation string,
reservation_unused_amortized_upfront_fee_for_billing_period double,
reservation_unused_normalized_unit_quantity double,
reservation_unused_quantity double,
reservation_unused_recurring_fee double,
reservation_upfront_value double,
resource_tags map<string,string>,
savings_plan_amortized_upfront_commitment_for_billing_period double,
savings_plan_end_time string,
savings_plan_instance_type_family string,
savings_plan_net_amortized_upfront_commitment_for_billing_period double,
savings_plan_net_recurring_commitment_for_billing_period double,
savings_plan_net_savings_plan_effective_cost double,
savings_plan_offering_type string,
savings_plan_payment_option string,
savings_plan_purchase_term string,
savings_plan_recurring_commitment_for_billing_period double,
savings_plan_region string,
savings_plan_savings_plan_a_r_n string,
savings_plan_savings_plan_effective_cost double,
savings_plan_savings_plan_rate double,
savings_plan_start_time string,
savings_plan_total_commitment_to_date double,
savings_plan_used_commitment double,
split_line_item_actual_usage double,
split_line_item_net_split_cost double,
split_line_item_net_unused_cost double,
split_line_item_parent_resource_id string,
split_line_item_public_on_demand_split_cost double,
split_line_item_public_on_demand_unused_cost double,
split_line_item_reserved_usage double,
split_line_item_split_cost double,
split_line_item_split_usage double,
split_line_item_split_usage_ratio double,
split_line_item_unused_cost double
)
PARTITIONED BY (billing_period string)
ROW FORMAT SERDE 'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'
STORED AS PARQUET
LOCATION 's3://cur-lxy-us-east-1/cur-v2/cur-v2/data/'
TBLPROPERTIES (
'projection.enabled' = 'true',
'projection.billing_period.type' = 'date',
'projection.billing_period.format' = 'yyyy-MM',
'projection.billing_period.range' = '2025-08,NOW',
'projection.billing_period.interval' = '1',
'projection.billing_period.interval.unit' = 'MONTHS',
'storage.location.template' = 's3://cur-lxy-us-east-1/cur-v2/cur-v2/data/BILLING_PERIOD=${billing_period}/'
);
随后即可在Athena默认数据库下,创建了名为cur_v2data_projected的表。
2、查询当月使用量并理解账单逻辑
在Athena上运行如下SQL。替换其中的月份即可获得不同月份结果。
-- 查询本月所有和Kiro相关的数据
SELECT identity_time_interval as time_range,
line_item_operation as cost_type,
ROUND(line_item_usage_amount, 2) as usage_amount,
product_usagetype as usage_type,
line_item_line_item_description as description,
product_sku as sku,
line_item_resource_id as user_id,
line_item_blended_cost as blended_cost,
line_item_unblended_cost as unblended_cost
FROM "default"."cur_v2data_projected"
WHERE billing_period = '2026-02'
AND product_location = 'US East (N. Virginia)'
AND line_item_product_code = 'Kiro'
ORDER BY time_range, usage_type
LIMIT 50;
查询结果类似如下:
# time_range cost_type usage_amount usage_type description sku user_id blended_cost unblended_cost
1 2026-02-01T00:00:00Z/2026-02-02T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
2 2026-02-02T00:00:00Z/2026-02-03T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
3 2026-02-02T02:00:00Z/2026-02-02T11:00:00Z Credits 3.31 USE1-KiroEnterprise-Credits $0.00 per Count for KiroEnterprise-Credits in US East (N. Virginia) G3T337J5U3BPYGDA arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.0 0.0
4 2026-02-03T00:00:00Z/2026-02-04T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
5 2026-02-03T02:00:00Z/2026-02-03T16:00:00Z Credits 1.02 USE1-KiroEnterprise-Credits $0.00 per Count for KiroEnterprise-Credits in US East (N. Virginia) G3T337J5U3BPYGDA arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.0 0.0
6 2026-02-04T00:00:00Z/2026-02-05T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
7 2026-02-04T02:00:00Z/2026-02-04T12:00:00Z Credits 18.96 USE1-KiroEnterprise-Credits $0.00 per Count for KiroEnterprise-Credits in US East (N. Virginia) G3T337J5U3BPYGDA arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.0 0.0
8 2026-02-05T00:00:00Z/2026-02-06T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
9 2026-02-05T02:00:00Z/2026-02-05T15:00:00Z Credits 19.41 USE1-KiroEnterprise-Credits $0.00 per Count for KiroEnterprise-Credits in US East (N. Virginia) G3T337J5U3BPYGDA arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.0 0.0
10 2026-02-06T00:00:00Z/2026-02-07T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
11 2026-02-06T03:00:00Z/2026-02-06T13:00:00Z Credits 3.36 USE1-KiroEnterprise-Credits $0.00 per Count for KiroEnterprise-Credits in US East (N. Virginia) G3T337J5U3BPYGDA arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.0 0.0
12 2026-02-07T00:00:00Z/2026-02-08T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
13 2026-02-08T00:00:00Z/2026-02-09T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
14 2026-02-09T00:00:00Z/2026-02-10T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
15 2026-02-10T00:00:00Z/2026-02-11T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
16 2026-02-11T00:00:00Z/2026-02-12T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
17 2026-02-12T00:00:00Z/2026-02-13T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
18 2026-02-13T00:00:00Z/2026-02-14T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
19 2026-02-14T00:00:00Z/2026-02-15T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
20 2026-02-15T00:00:00Z/2026-02-16T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
21 2026-02-16T00:00:00Z/2026-02-17T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
22 2026-02-17T00:00:00Z/2026-02-18T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
23 2026-02-18T00:00:00Z/2026-02-19T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
24 2026-02-19T00:00:00Z/2026-02-20T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
25 2026-02-20T00:00:00Z/2026-02-21T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
26 2026-02-21T00:00:00Z/2026-02-22T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
27 2026-02-22T00:00:00Z/2026-02-23T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
28 2026-02-23T00:00:00Z/2026-02-24T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
29 2026-02-24T00:00:00Z/2026-02-25T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
30 2026-02-25T00:00:00Z/2026-02-26T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
31 2026-02-26T00:00:00Z/2026-02-27T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
32 2026-02-27T00:00:00Z/2026-02-28T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142858 0.7142858
33 2026-02-28T00:00:00Z/2026-03-01T00:00:00Z monthly-subscription 0.04 USE1-KiroEnterprise-Pro $20.00 per Count for KiroEnterprise-Pro in US East (N. Virginia) JEYNABEZAXQAYCDW arn:aws:identitystore:::user/843884c8-00c1-7046-e4e8-7ba5acc6cfc7 0.7142834 0.7142834
如何理解这部分数据呢?这里解释如下:
- 首先,user_id不是用户名也不是邮箱,而是经典的AWS的ARN资源ID,这是对应的Kiro订阅时候的IAM Identity Center中的user的ARN,在下文可通过关联查询获取用户真实姓名或邮箱。
- 其次,可看到两种订阅类型,一种是
Credit,一种是monthly-subscription,分别解释如下。 - 费用类型为
Credit的这一列,是本用户在最近一个计费窗口(例如24小时,以创建CUR选的颗粒度为准)的使用量,例如第三行amount 3.31表示用了Credit数量是3.31,最后blended_cost显示为0表示这个用户没有超过本月Kiro Plan包含的Credit数量,因此这部分Credit使用量被记录,但不额外收费。 - 费用类型为
monthly-subscription的这一列,表示一个用户订阅后,会从当前日期开始,预先生成几十条本月订阅记录。例如订阅Plan是Pro级别,预期收费$20一个月,那么分拆到30天,每天的amount就是0.03个数量(四舍五入得0.4,在Athena中用了截断),最后blended_cost显示为本条计费是$0.7,那么乘以30就正好是每月$20。本文的例子是显示的一个正月,如果是月中15日做的订阅,那么这里monthly-subscription类型的费用就只有15条,本月总计收取的monthly-subscription就是$10。这就是Kiro从月中订阅,仅从当日开始计费的逻辑对应的原始账单数据。
理解了以上账单数据,那么就可以卡是编写复杂一些的查询逻辑。
3、查询本月内每个用户自己的Kiro Credit使用情况
WITH user_plans AS (
SELECT DISTINCT
SPLIT_PART(line_item_resource_id, 'user/', 2) as user_id,
CASE
WHEN product_usagetype LIKE '%Pro+%' THEN 'Pro+'
WHEN product_usagetype LIKE '%Power%' THEN 'Power'
WHEN product_usagetype LIKE '%Pro%' THEN 'Pro'
END as subscription_plan
FROM "default"."cur_v2data_projected"
WHERE
billing_period = '2026-02'
AND line_item_product_code = 'Kiro'
AND line_item_operation = 'monthly-subscription'
)
SELECT
p.subscription_plan,
CASE
WHEN p.subscription_plan = 'Pro' THEN 1000
WHEN p.subscription_plan = 'Pro+' THEN 2000
WHEN p.subscription_plan = 'Power' THEN 10000
END as plan_credits,
p.user_id,
ROUND(SUM(c.line_item_usage_amount),2) as total_credits
FROM "default"."cur_v2data_projected" c
JOIN user_plans p ON SPLIT_PART(c.line_item_resource_id, 'user/', 2) = p.user_id
WHERE
c.billing_period = '2026-02'
AND c.line_item_product_code = 'Kiro'
AND c.line_item_operation = 'Credits'
GROUP BY
p.subscription_plan,
p.user_id
ORDER BY
CASE
WHEN p.subscription_plan = 'Pro' THEN 1
WHEN p.subscription_plan = 'Pro+' THEN 2
WHEN p.subscription_plan = 'Power' THEN 3
END,
p.user_id
返回数据格式如下:(注意这是本月截止到最新CUR数据刷新的日期)
# subscription_plan plan_credits user_id total_credits
1 Pro 1000 843884c8-00c1-7046-e4e8-7ba5acc6cfc7 46.06
注意:以上SQL查询结果中,user_id是对应的Kiro订阅时候的IAM Identity Center中的user的id。这个id不是用户名也不是邮箱,下文可通过关联查询获取用户真实姓名或邮箱。
4、查询哪些用户超过了订阅的Plan的总和(如果没有超额则显示为空)
WITH user_plans AS (
SELECT DISTINCT
SPLIT_PART(line_item_resource_id, 'user/', 2) as user_id,
CASE
WHEN product_usagetype LIKE '%Pro+%' THEN 'Pro+'
WHEN product_usagetype LIKE '%Power%' THEN 'Power'
WHEN product_usagetype LIKE '%Pro%' THEN 'Pro'
END as subscription_plan
FROM "default"."cur_v2data_projected"
WHERE
billing_period = '2026-02'
AND line_item_product_code = 'Kiro'
AND line_item_operation = 'monthly-subscription'
),
user_usage AS (
SELECT
p.subscription_plan,
CASE
WHEN p.subscription_plan = 'Pro' THEN 1000
WHEN p.subscription_plan = 'Pro+' THEN 2000
WHEN p.subscription_plan = 'Power' THEN 10000
END as plan_credits,
p.user_id,
ROUND(SUM(c.line_item_usage_amount),2) as total_credits
FROM "default"."cur_v2data_projected" c
JOIN user_plans p ON SPLIT_PART(c.line_item_resource_id, 'user/', 2) = p.user_id
WHERE
c.billing_period = '2026-02'
AND c.line_item_product_code = 'Kiro'
AND c.line_item_operation = 'Credits'
GROUP BY
p.subscription_plan,
p.user_id
)
SELECT
subscription_plan,
plan_credits,
user_id,
total_credits,
total_credits - plan_credits as overage
FROM user_usage
WHERE total_credits > plan_credits
ORDER BY
CASE
WHEN subscription_plan = 'Pro' THEN 1
WHEN subscription_plan = 'Pro+' THEN 2
WHEN subscription_plan = 'Power' THEN 3
END,
user_id
如果有用户超额,则显示用户清单,如果没有超额,则显示为空。
注意:以上SQL查询结果中,user_id是对应的Kiro订阅时候的IAM Identity Center中的user的id。这个id不是用户名也不是邮箱,下文可通过关联查询获取用户真实姓名或邮箱。
四、建立Kiro的用户名和用户ID的映射关系
本文采用从IAM Identity Center手工导出一个最新用户清单的办法,另外新建一个Athena表,然后做联合查询完成userid和用户名的对应关系。如果需要的话,稍微修改下,即可完成用户邮箱和用户id的映射。
1、使用AWSCLI查询IAM Identity Center上的用户ID映射关系
在配置了AWSCLI的环境上,使用如下命令,查询AWS当前使用的SSO的Instance ID。
aws sso-admin list-instances --region us-east-1
返回结果如下:
{
"Instances": [
{
"InstanceArn": "arn:aws:sso:::instance/ssoins-72236887c48a0b06",
"IdentityStoreId": "d-9066195b8c",
"OwnerAccountId": "133129065110",
"CreatedDate": "2025-12-22T11:36:00.192000+08:00",
"Status": "ACTIVE"
}
]
}
以上信息中的IdentityStoreId就是我们需要的信息。将这个ID复制下来,构建如下AWSCLI命令,导出用户清单。
aws identitystore list-users \
--identity-store-id d-9066195b8c \
--region us-east-1 \
--query 'Users[*].{Username:UserName,UserId:UserId}' \
--output json | jq -c '.[]' > user-list.jsonl
这个命令会将当前IAM Identity Center上的所有用户输出到一个JSON List文件。如果用户数量较多,AWSCLI会自动分批获取,时间会比较长。
生成的jsonl文件格式如下。
{"Username":"user01","UserId":"843884c8-00c1-7046-e4e8-7ba5acc6cfc7"}
{"Username":"user02","UserId":"04d86408-4001-7047-01d1-077885ab54fa"}
现在在执行AWSCLI的本地环境中获得了user-list.jsonl文件。接下来将这个文件导入到Athena的表中方便SQL查询。
2、在Athena内创建用户名和用户ID映射表
将以上文件上传到S3存储桶,例如路径是s3://cur-lxy-us-east-1/user-list/。然后登陆到AWS控制台,进入Athena服务,执行如下命令创建新表
CREATE EXTERNAL TABLE default.identity_center_users (
Username string,
UserId string
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
WITH SERDEPROPERTIES (
'dots.in.keys' = 'false',
'case.insensitive' = 'true',
'mapping' = 'true'
)
LOCATION 's3://cur-lxy-us-east-1/user-list/'
由此在Athena的default数据库内,创建了一个名为identity_center_users的表。
创建表完毕后,查询测试:
SELECT * FROM "default"."identity_center_users" limit 10;
可看到返回结果正常。
# username userid
1 user01 843884c8-00c1-7046-e4e8-7ba5acc6cfc7
2 user02 04d86408-4001-7047-01d1-077885ab54fa
五、将CUR V2查询结果和用户映射表关联输出友好查询结果
以上两个步骤,分别有了Kiro用户使用Credit情况和Kiro用户名映射表两种类型的数据,由此可以拼接在一起获得友好查询结果。
1、查询每个用户的Credit使用情况(拼接用户名)
WITH user_plans AS (
SELECT DISTINCT
SPLIT_PART(line_item_resource_id, 'user/', 2) as user_id,
CASE
WHEN product_usagetype LIKE '%Pro+%' THEN 'Pro+'
WHEN product_usagetype LIKE '%Power%' THEN 'Power'
WHEN product_usagetype LIKE '%Pro%' THEN 'Pro'
END as subscription_plan
FROM "default"."cur_v2data_projected"
WHERE
billing_period = '2026-02'
AND line_item_product_code = 'Kiro'
AND line_item_operation = 'monthly-subscription'
)
SELECT
p.subscription_plan,
CASE
WHEN p.subscription_plan = 'Pro' THEN 1000
WHEN p.subscription_plan = 'Pro+' THEN 2000
WHEN p.subscription_plan = 'Power' THEN 10000
END as plan_credits,
u.username,
ROUND(SUM(c.line_item_usage_amount),2) as total_credits
FROM "default"."cur_v2data_projected" c
JOIN user_plans p ON SPLIT_PART(c.line_item_resource_id, 'user/', 2) = p.user_id
LEFT JOIN "default"."identity_center_users" u ON p.user_id = u.userid
WHERE
c.billing_period = '2026-02'
AND c.line_item_product_code = 'Kiro'
AND c.line_item_operation = 'Credits'
GROUP BY
p.subscription_plan,
u.username
ORDER BY
CASE
WHEN p.subscription_plan = 'Pro' THEN 1
WHEN p.subscription_plan = 'Pro+' THEN 2
WHEN p.subscription_plan = 'Power' THEN 3
END,
u.username
返回结果如下:
# subscription_plan plan_credits username total_credits
1 Pro 1000 user01 46.06
2、查询超过Plan内Credit使用的用户(拼接用户名,如果没有则显示空)
WITH user_plans AS (
SELECT DISTINCT
SPLIT_PART(line_item_resource_id, 'user/', 2) as user_id,
CASE
WHEN product_usagetype LIKE '%Pro+%' THEN 'Pro+'
WHEN product_usagetype LIKE '%Power%' THEN 'Power'
WHEN product_usagetype LIKE '%Pro%' THEN 'Pro'
END as subscription_plan
FROM "default"."cur_v2data_projected"
WHERE
billing_period = '2026-02'
AND line_item_product_code = 'Kiro'
AND line_item_operation = 'monthly-subscription'
),
user_usage AS (
SELECT
p.subscription_plan,
CASE
WHEN p.subscription_plan = 'Pro' THEN 1000
WHEN p.subscription_plan = 'Pro+' THEN 2000
WHEN p.subscription_plan = 'Power' THEN 10000
END as plan_credits,
p.user_id,
SUM(c.line_item_usage_amount) as total_credits
FROM "default"."cur_v2data_projected" c
JOIN user_plans p ON SPLIT_PART(c.line_item_resource_id, 'user/', 2) = p.user_id
WHERE
c.billing_period = '2026-02'
AND c.line_item_product_code = 'Kiro'
AND c.line_item_operation = 'Credits'
GROUP BY
p.subscription_plan,
p.user_id
)
SELECT
uu.subscription_plan,
uu.plan_credits,
u.username,
uu.total_credits,
uu.total_credits - uu.plan_credits as overage
FROM user_usage uu
LEFT JOIN "default"."identity_center_users" u ON uu.user_id = u.userid
WHERE uu.total_credits > uu.plan_credits
ORDER BY
CASE
WHEN uu.subscription_plan = 'Pro' THEN 1
WHEN uu.subscription_plan = 'Pro+' THEN 2
WHEN uu.subscription_plan = 'Power' THEN 3
END,
u.username
如果所有用户都没有超额使用,则查询结果为空。
3、查询今年每个用户在每个月的使用情况
现在考虑一种更复杂的情况,用户user01在1月份订阅Pro Plan(内置1000 Credit),二月份订阅Pro+ Plan(内置2000 Credit),此外还有user02等几百个用户。现在需要查询他们在今年不同月份的情况。
构建如下一个复杂SQL,关联两张表查询。
WITH user_plans AS (
SELECT DISTINCT
billing_period,
SPLIT_PART(line_item_resource_id, 'user/', 2) as user_id,
CASE
WHEN product_usagetype LIKE '%Pro+%' THEN 'Pro+'
WHEN product_usagetype LIKE '%Power%' THEN 'Power'
WHEN product_usagetype LIKE '%Pro%' THEN 'Pro'
END as subscription_plan
FROM "default"."cur_v2data_projected"
WHERE
billing_period BETWEEN '2026-01' AND '2026-12'
AND line_item_product_code = 'Kiro'
AND line_item_operation = 'monthly-subscription'
),
user_first_sub AS (
SELECT
billing_period,
SPLIT_PART(line_item_resource_id, 'user/', 2) as user_id,
MIN(identity_time_interval) as first_interval
FROM "default"."cur_v2data_projected"
WHERE
billing_period BETWEEN '2026-01' AND '2026-12'
AND line_item_product_code = 'Kiro'
AND line_item_operation = 'monthly-subscription'
GROUP BY billing_period, SPLIT_PART(line_item_resource_id, 'user/', 2)
)
SELECT
c.billing_period,
u.username,
CASE
WHEN SUBSTR(fs.first_interval, 1, 10) != p.billing_period || '-01' THEN 'Y'
ELSE 'N'
END as new_user,
p.subscription_plan,
CASE
WHEN p.subscription_plan = 'Pro' THEN 1000
WHEN p.subscription_plan = 'Pro+' THEN 2000
WHEN p.subscription_plan = 'Power' THEN 10000
END as plan_credits,
ROUND(SUM(c.line_item_usage_amount), 2) as used_credits
FROM "default"."cur_v2data_projected" c
JOIN user_plans p
ON SPLIT_PART(c.line_item_resource_id, 'user/', 2) = p.user_id
AND c.billing_period = p.billing_period
LEFT JOIN user_first_sub fs
ON p.user_id = fs.user_id
AND p.billing_period = fs.billing_period
LEFT JOIN "default"."identity_center_users" u
ON p.user_id = u.userid
WHERE
c.billing_period BETWEEN '2026-01' AND '2026-12'
AND c.line_item_product_code = 'Kiro'
AND c.line_item_operation = 'Credits'
GROUP BY
c.billing_period,
u.username,
p.subscription_plan,
fs.first_interval,
p.billing_period
ORDER BY
u.username,
c.billing_period
LIMIT 50
查询结果如下:
# billing_period username new_user subscription_plan plan_credits used_credits
1 2026-01 user01 Y Pro 1000 18.53
2 2026-02 user01 N Pro 1000 46.06
在以上查询结果中,会列出2026年全年所有月份,由于本文编写是2月,因此只有两条。用户方面,会列出这个CUR中所有Kiro订阅用户(并将ARN关联额外用户名表格查询),同时还会给出本用户在本月订阅的级别、包含的Credit、实际使用的Credit。此外,还增加了一个new_user字段,显示Y表示这个用户是本月新增的,显示N则表示这个用户是上月就开通了。由此满足查询要求。
4、查询每月TOP5用户
现在调整需求为生成本月TOP5 Credit用量的用户。执行如下SQL:
WITH user_plans AS (
SELECT DISTINCT
billing_period,
SPLIT_PART(line_item_resource_id, 'user/', 2) as user_id,
CASE
WHEN product_usagetype LIKE '%Pro+%' THEN 'Pro+'
WHEN product_usagetype LIKE '%Power%' THEN 'Power'
WHEN product_usagetype LIKE '%Pro%' THEN 'Pro'
END as subscription_plan
FROM "default"."cur_v2data_projected"
WHERE
billing_period = '2026-02'
AND line_item_product_code = 'Kiro'
AND line_item_operation = 'monthly-subscription'
)
SELECT
c.billing_period,
ROW_NUMBER() OVER (ORDER BY SUM(c.line_item_usage_amount) DESC) as rank,
u.username,
p.subscription_plan,
CASE
WHEN p.subscription_plan = 'Pro' THEN 1000
WHEN p.subscription_plan = 'Pro+' THEN 2000
WHEN p.subscription_plan = 'Power' THEN 10000
END as plan_credits,
ROUND(SUM(c.line_item_usage_amount), 2) as used_credits
FROM "default"."cur_v2data_projected" c
JOIN user_plans p
ON SPLIT_PART(c.line_item_resource_id, 'user/', 2) = p.user_id
AND c.billing_period = p.billing_period
LEFT JOIN "default"."identity_center_users" u
ON p.user_id = u.userid
WHERE
c.billing_period = '2026-02'
AND c.line_item_product_code = 'Kiro'
AND c.line_item_operation = 'Credits'
GROUP BY
c.billing_period,
u.username,
p.subscription_plan
ORDER BY
used_credits DESC
LIMIT 5
即可获得结果,结果类似如下:
# billing_period rank username subscription_plan plan_credits used_credits
1 2026-02 1 user01 Pro 1000 65.62
2 2026-02 2 userxxx Pro 1000 50.22
3 2026-02 3 userxxx Pro 1000 45.11
4 2026-02 4 userxxx Pro 1000 30.68
5 2026-02 5 userxxx Pro 1000 21.99
六、参考文档
https://kiro.dev/docs/enterprise/monitor-and-track/dashboard/#dashboard-metrics
注:本文SQL由Kiro CLI生成,点击这里下载Kiro CLI:kiro.dev
-完-
最后修改于 2026-01-27