跳到主要内容
版本:v1.4.1(当前)

示例:FinOps 成本分摊标签

目标: 为 FinOps(云财务运营)或财务团队生成一份报告,逐个资源显示成本分摊标签是否存在且有效。

你需要: 只读凭证。标签只有在你于 AWS Billing and Cost Management 控制台中将其激活为成本分摊标签之后, 才会出现在 AWS 成本报告中。InvenTag 显示哪些资源带有这些标签。它不读取你的账单。可选的 --enable-cost-analysis 会添加成本估算。

未针对 AWS 验证:标签只有在你把它们激活为成本分摊标签之后才会出现在成本报告中。

未针对真实的 AWS 验证:--enable-cost-analysis 的成本估算。

模板​

finops-cost-report(一个报告模板)把 CostCenter、Owner、Project 和 Environment 显示为列, 并启用 finops-cost-allocation 标签策略:

标签键finops-cost-allocation 中的规则
CostCenterCC- 加四位数字,例如 CC-1234
Owner任意值
Project任意值
Environmentprod、staging、dev、test 或 sandbox

如果你的成本中心格式不同,可以调整策略并保留报告:

.inventag/templates/our-cost-tags.yaml
format_version: 1
kind: tag-policy
name: our-cost-tags
description: Our cost centres are five-digit numbers
extends: finops-cost-allocation
spec:
required_tags:
- key: CostCenter
pattern: "[0-9]{5}"

命令​

Terminal
inventag --template finops-cost-report --create-excel --create-word --account-regions us-east-1
# with your own policy:
inventag --template finops-cost-report --template our-cost-tags --create-excel

输出​

输出
inventag - WARNING - - No account specification method provided. Using default AWS credentials.
Wrote bom_output/tag_compliance_20261112_090000.json
Wrote bom_output/multi_account_bom_20261112_090000.docx
Wrote bom_output/multi_account_bom_20261112_090000.xlsx
Tag policy 'finops-cost-allocation': 1 of 23 resources compliant (4.3%), 22 non-compliant, 14 out of scope.

工作表: Summary、ATHENA、DYNAMODB、EC2、EVENTS、IAM、KMS、LAMBDA、S3、VPC、Tag Compliance

Tag Compliance 工作表的前几行:

AccountRegionServiceTypeResourceARNStatusMissing tagsProblems
123456789012us-east-1DYNAMODBTableacme-ordersarn:aws:dynamodb:us-east-1:123456789012:table...Non-compliantCostCenter, Project
123456789012us-east-1EC2Instanceacme-web-1arn:aws:ec2:us-east-1:123456789012:instance/i...Non-compliantCostCenter, Project
123456789012us-east-1EC2Volumeacme-build-cachearn:aws:ec2:us-east-1:123456789012:volume/vol...Non-compliantCostCenter, Owner, Project, Environment
123456789012globalIAMRoleacme-orders-api-rolearn:aws:iam::123456789012:role/acme-orders-ap...Non-compliantCostCenter, Owner, Project, Environment

Tag Compliance 工作表:每个资源一行,包含账户、区域、服务、类型、资源、ARN、状态、缺少的标签和问题,其后是策略规则表(示例数据)

Word 文档的 Tag compliance 章节:

文档大纲:

  • Cost Allocation Tag Report(标题)
  • Summary
  • Tag compliance
    • Required tags
    • Non-compliant resources
  • Resources by service
  • About this report

文档中的一个表格:

Tag keyRuleMissingInvalid value
CostCenterMatches: CC-[0-9]{4}201
OwnerAny value170
ProjectAny value210
EnvironmentOne of: prod, staging, dev, test, sandbox (an...171

JSON 文件:

tag_compliance_20261112_090000.json (one resource shown)
{
"policy": "finops-cost-allocation",
"description": "Requires CostCenter, Owner, Project and Environment so spend can be allocated.",
"summary": {
"checked": 23,
"compliant": 1,
"non_compliant": 22,
"out_of_scope": 14,
"percent_compliant": 4.3,
"missing_by_key": {
"CostCenter": 20,
"Owner": 17,
"Project": 21,
"Environment": 17
},
"invalid_by_key": {
"CostCenter": 1,
"Owner": 0,
"Project": 0,
"Environment": 1
}
},
"non_compliant_resources": [
{
"account": "123456789012",
"service": "S3",
"resource_type": "Bucket",
"resource_id": "acme-reports",
"arn": "arn:aws:s3:::acme-reports",
"region": "us-east-1",
"missing": [],
"invalid": [
"CostCenter: '1234' does not match CC-[0-9]{4}",
"Environment: 'Production' is not one of prod, staging, dev, test, sandbox"
]
}
]
}

下载示例标签合规 JSON(9 KB,示例数据)

下一步​

  • 把 Word 文档发给预算负责人。其中的 Tag compliance 章节列出了不合规的资源。
  • 每周跟踪进展:在 CI/CD 中运行 InvenTag。