示例:盘点组织中的每个账户
目标: 一份覆盖所有账户的报告,包含 Account 列和标签检查。
你需要:
- 每个账户中都有一个同名角色(这里是
InvenTagReadOnly),并附带 只读策略; - 一个可以代入这些角色的身份的凭证,例如管理账户或委派的安全账户中的凭证。
未针对真实的 AWS 验证:管理账户或委派账户可以代入这些角色。
模板
列出你的账户:
Terminal
aws organizations list-accounts --query "Accounts[?Status=='ACTIVE'].[Id,Name]" --output text
未针对真实的 AWS 验证:aws organizations list-accounts 命令及其列出的账户。
复制内置模板,并填入你的账户:
Terminal
inventag templates init org-multi-account --output .inventag/templates/our-org.yaml
.inventag/templates/our-org.yaml
format_version: 1
kind: config
name: our-org
description: Every active account, read-only
spec:
accounts:
- account_id: "111111111111"
account_name: Production
role_arn: arn:aws:iam::111111111111:role/InvenTagReadOnly
- account_id: "222222222222"
account_name: Staging
role_arn: arn:aws:iam::222222222222:role/InvenTagReadOnly
- account_id: "333333333333"
account_name: Shared services
role_arn: arn:aws:iam::333333333333:role/InvenTagReadOnly
regions: [us-east-1]
outputs: [excel, word]
report_template: standard-bom
tag_policy: finops-cost-allocation
max_concurrent_accounts: 4
命令
Terminal
inventag templates validate our-org
inventag --template our-org
输出
占位符 ID 还在时,validate 会给出警告:
输出
WARNING ~/acme-infra/.inventag/templates/our-org.yaml: account IDs 111111111111, 222222222222, 333333333333 look like placeholders; replace them with your own
OK ~/acme-infra/.inventag/templates/our-org.yaml (config 'our-org')
运行结果如下,三个虚构账户中各有一个示例存储桶:
输出
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': 0 of 39 resources compliant (0.0%), 39 non-compliant, 42 out of scope.
工作表: Summary、ATHENA、EVENTS、KMS、S3、VPC、Tag Compliance
Summary 工作表:
AWS Resource Inventory
Bill of materials generated by InvenTag
Generated: 2026-11-12 09:00 UTC
Accounts: 3 Regions: 1
| Service | Resources | Share |
|---|---|---|
| ATHENA | 3 | 3.7% |
| EVENTS | 3 | 3.7% |
| KMS | 42 | 51.9% |
| S3 | 3 | 3.7% |
| VPC | 30 | 37.0% |
| Total | 81 | 100.0% |
工作表: Summary、ATHENA、EVENTS、KMS、S3、VPC、Tag Compliance
S3 工作表的前几行:
| Account | Region | Service | Type | Name | ID | ARN | ... |
|---|---|---|---|---|---|---|---|
| 111111111111 | us-east-1 | S3 | Bucket | acme-production-artifacts | acme-production-artifacts | arn:aws:s3:::acme-production-artifacts | ... |
| 333333333333 | us-east-1 | S3 | Bucket | acme-shared-services-artifacts | acme-shared-services-artifacts | arn:aws:s3:::acme-shared-services-artifacts | ... |
| 222222222222 | us-east-1 | S3 | Bucket | acme-staging-artifacts | acme-staging-artifacts | arn:aws:s3:::acme-staging-artifacts | ... |
该工作表共有 9 列;此处显示前 7 列。
下一步
- 如果某个账户失败,InvenTag 会记录错误、报告其他账户,并仍以退出码 0 结束,
所以请检查日志。加上
--fail-on-account-error则会在写出报告之后以退出码 5 结束。如果所有账户都失败,运行会以退出码 1 结束。 - 超时的账户会保留时限之前已找到的资源。在有账户失败的运行之后,用同一条命令再加上
--resume运行,只扫描其余账户(已完成的账户会被复用)。 - 扫描多个账户介绍了调优选项。