跳到主要內容
版本:v1.2.0

Scan several accounts

Who this is for: you look after more than one AWS account and want one consolidated report.

What you can do after reading: list your accounts once and scan them all in one run.

How it works​

InvenTag reads a list of accounts. For each one it gets credentials, either from a named AWS CLI profile or by assuming an IAM role from the identity you run it with. It scans each account, up to four at a time by default, and writes one report with an Account column.

InvenTag does not list the accounts in your AWS Organization for you. You write the list.

Create a read-only role in every account​

Follow Set up read-only access. Use the same role name everywhere, for example InvenTagReadOnly.

Get your account list​

From the management account, or a delegated administrator account:

Shell
aws organizations list-accounts \
--query "Accounts[?Status=='ACTIVE'].[Id,Name]" --output text

Write the list as a config template​

Shell
inventag templates init org-multi-account --output .inventag/templates/our-org.yaml

Edit the accounts section. Each account needs its 12-digit ID in quotes and either a role_arn or a profile_name:

YAML
spec:
accounts:
- account_id: "123456789012"
account_name: Production
role_arn: arn:aws:iam::123456789012:role/InvenTagReadOnly
- account_id: "210987654321"
account_name: Development
profile_name: dev-readonly
regions: [us-east-1, eu-west-1]

Check it, then run it:

Shell
inventag templates validate our-org
inventag --template our-org

validate catches the common mistakes: unquoted account IDs, a role ARN that points at a different account than account_id, and access keys in the file (not allowed in templates). With the placeholder IDs still in place it says (sample data):

Output
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')

A run across the three sample accounts:

Output
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.

Sheets: Summary, ATHENA, EVENTS, KMS, S3, VPC, Tag Compliance

Summary sheet:

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%

Or use an accounts file​

The --accounts-file option also works, and it accepts access keys (avoid them if you can). If every account uses the same role name, you don't need to write each ARN:

Terminal
inventag --accounts-file accounts.yaml --cross-account-role InvenTagReadOnly --create-excel

The accounts file format is in Configuration files.

Shell
inventag --accounts-file accounts.yaml --create-excel

Tune the run​

SettingConfig template fieldFlag
Accounts scanned at once (default 4)max_concurrent_accounts--max-concurrent-accounts
Seconds allowed per account (default 1800, at least 60)account_processing_timeout--account-processing-timeout
One account at a timeparallel_processing: false--disable-parallel-processing

If one account fails, for example because its role cannot be assumed, InvenTag logs the error and reports the accounts that worked. It does not fall back to your default credentials for that account. The Summary sheet of the Excel report and the Word report have a "Run notes" section that names each account that was not scanned, and why. The log has the same list:

Text
1 account(s) were not scanned, or only partly. The report does not include them:
- 222222222222 (Dev): Context establishment failed: Role assumption failed for account 222222222222: An error occurred (AccessDenied) when calling the AssumeRole operation: ...

The run still exits with code 0. Add --fail-on-account-error to exit with code 5 when any account could not be scanned completely. The reports are still written. If every account fails, the run exits with code 1 and writes no report.

An account that runs out of time (--account-processing-timeout) counts as failed, but the resources it found before the limit stay in the report, and the notes say that the account is incomplete. See Time limit and parallel accounts.

Continue after a failure​

InvenTag saves the accounts that finished. After you fix the cause, run the same command with --resume to scan only the others:

Shell
inventag --accounts-file accounts.yaml --create-excel --resume

InvenTag reuses saved results of the same command (same accounts, regions, services and filters) that are not older than --resume-max-age-hours (default 24, at most 168). See Continue after a failed run.

Check the accounts file​

InvenTag reads the accounts file as UTF-8 text, with or without a byte order mark, from a file of at most 1 MiB. It stops with exit code 1 and names the problem when:

  • the file is empty, or its top level is a list and not a set of key: value pairs;
  • a key is written twice (the message gives the line, for example accounts file accounts.yaml:3: duplicate key 'accounts');
  • the file type is not .json, .yaml or .yml;
  • an account has no non-empty account_id, or a field has the wrong type.

If the file holds secret_access_key or session_token and other users can read it, InvenTag warns and tells you to run chmod 600. Use profile_name or role_arn instead of keys. Check a file without scanning: inventag --accounts-file accounts.yaml --validate-config-only --skip-credential-validation.

Two option mistakes stop the run with exit code 2: --accounts-file together with --accounts-prompt, and a full role ARN in --cross-account-role together with an accounts file (give a role name there, or put role_arn in the file).

Next steps​