跳到主要內容
版本:v1.4.1(目前)

範例:盤點組織中的每個帳戶

目標: 一份覆蓋所有帳戶的報告,包含 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

ServiceResourcesShare
ATHENA33.7%
EVENTS33.7%
KMS4251.9%
S333.7%
VPC3037.0%
Total81100.0%

工作表: Summary、ATHENA、EVENTS、KMS、S3、VPC、Tag Compliance

S3 工作表的前幾列:

AccountRegionServiceTypeNameIDARN...
111111111111us-east-1S3Bucketacme-production-artifactsacme-production-artifactsarn:aws:s3:::acme-production-artifacts...
333333333333us-east-1S3Bucketacme-shared-services-artifactsacme-shared-services-artifactsarn:aws:s3:::acme-shared-services-artifacts...
222222222222us-east-1S3Bucketacme-staging-artifactsacme-staging-artifactsarn:aws:s3:::acme-staging-artifacts...

該工作表共有 9 欄;此處顯示前 7 欄。

下一步​

  • 如果某個帳戶失敗,InvenTag 會記錄錯誤、報告其他帳戶,並仍以結束代碼 0 結束, 所以請檢查日誌。加上 --fail-on-account-error 則會在寫出報告之後以結束代碼 5 結束。如果所有帳戶都失敗,執行會以結束代碼 1 結束。
  • 超時的帳戶會保留時限之前已找到的資源。在有帳戶失敗的執行之後,用同一條命令再加上 --resume 執行,只掃描其餘帳戶(已完成的帳戶會被複用)。
  • 掃描多個帳戶介紹了調優選項。