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:
aws organizations list-accounts \
--query "Accounts[?Status=='ACTIVE'].[Id,Name]" --output text
Not verified against real AWS: the aws organizations list-accounts command and the accounts it lists.
Write the list as a config template
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:
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:
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):
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:
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
| 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% |
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:
inventag --accounts-file accounts.yaml --cross-account-role InvenTagReadOnly --create-excel
The accounts file format is in Configuration files.
inventag --accounts-file accounts.yaml --create-excel
Tune the run
| Setting | Config template field | Flag |
|---|---|---|
| Accounts scanned at once (default 4) | max_concurrent_accounts | --max-concurrent-accounts |
| Most AWS requests in flight for the whole run (default 64, 1 to 256) | concurrency | --concurrency |
| Seconds allowed per account (default 1800, at least 60) | account_processing_timeout | --account-processing-timeout |
| One account at a time | parallel_processing: false | --disable-parallel-processing |
InvenTag checks the credentials of the accounts in parallel, up to
--max-concurrent-accounts at a time. The results keep the order of your
account list. A profile with mfa_serial asks for a code, so while a terminal
is attached, InvenTag handles such a profile first and one at a time.
The limit of --concurrency is shared by all accounts. One account never has
more than 16 requests in flight. Rows and analysis sheets follow the order of
your account list, not the order in which the accounts finish. See
Concurrency.
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
scan that account with your default credentials, unless those credentials belong to 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:
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 an account could not be scanned or ran out of time. 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:
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.
An account whose session expired part-way is not saved, so --resume scans it again.
In a GitLab CI/CD pipeline
Not verified against a GitLab runner or a real AWS account: this pipeline has not run on GitLab. Its YAML and its inventag command line are checked when the docs are built. Its job ran locally with gitlab-ci-local 4.77.1 (with a stand-in for rsync) against mocked AWS, with a dummy token.
This job scans every account of accounts.yaml on a pipeline schedule. It signs in to one role through OIDC, and InvenTag then assumes the role InvenTagReadOnly in each account. The job uses --resume, so the cache and a Retry can finish the accounts that were missing. accounts.yaml is committed to the repository, so it must hold account IDs and names and no access keys. Before you use it:
- Create the role that GitLab signs in to and the CI/CD variable
AWS_ROLE_ARN, as described in Run InvenTag in CI/CD. The same section explains how to create the pipeline schedule. - Give that role
sts:AssumeRoleon theInvenTagReadOnlyrole of each account, and let each of those roles trust it: see Set up read-only access. The policy fileconfig/defaults/iam-policy-read-only.jsonhas nosts:AssumeRolestatement, so you add one.
# .gitlab-ci.yml
stages:
- inventory
org-inventory:
stage: inventory
image: python:3.12
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_PIPELINE_SOURCE == "web"
timeout: 3 hours # the ID token expires with the job
id_tokens:
GITLAB_OIDC_TOKEN:
aud: sts.amazonaws.com
variables:
AWS_DEFAULT_REGION: us-east-1
cache:
key: inventag-state
paths:
- bom_output/state/ # saved results of finished accounts, for --resume
when: always # save them when the job fails, too
script:
- pip install "inventag-aws==1.4.1" # pin a release
- export AWS_WEB_IDENTITY_TOKEN_FILE="$(mktemp)"
- printf '%s' "$GITLAB_OIDC_TOKEN" > "$AWS_WEB_IDENTITY_TOKEN_FILE"
- |
inventag --accounts-file accounts.yaml --cross-account-role InvenTagReadOnly \
--create-excel --resume --resume-max-age-hours 12 \
--fail-on-account-error --fail-if-empty
artifacts:
when: always # keep the reports of the accounts that worked
paths:
- bom_output/
expire_in: 30 days
The lines that every GitLab example shares are explained in Run InvenTag in CI/CD. This table covers what is specific to this example.
| Part | What it does |
|---|---|
--accounts-file accounts.yaml --cross-account-role InvenTagReadOnly | The job signs in to one role through OIDC. From there InvenTag assumes the role InvenTagReadOnly in each account of the file. |
cache: with key: inventag-state, paths: - bom_output/state/, when: always | InvenTag saves the accounts that finished in bom_output/state/partial/ (Continue after a failed run). A new job starts with an empty folder, so the cache carries bom_output/state/ to the next job. when: always saves the cache when the job fails; the default saves it only on success (GitLab: cache:when, GitLab: caching). |
--resume --resume-max-age-hours 12 | After a failed run, press Retry on the job (or wait for the next run): only the accounts that are missing are scanned. 12 is on purpose. With the default of 24 hours, the next night's run could reuse last night's results of a run that failed. With no saved results, --resume changes nothing. If the cache is not there, every account is scanned again: slower, never wrong. The rules for reusing saved results are in Continue after a failed run. |
--fail-on-account-error --fail-if-empty | Exit code 5 when an account could not be scanned; exit code 6 when no resources were found. The reports of the other accounts are written and kept by artifacts: when: always (GitLab: artifacts:when). |
timeout: 3 hours | The longest a job can run on GitLab-hosted runners of GitLab.com (GitLab: hosted runners). |
Parts that the local run did not cover:
- Not verified against GitLab or AWS: GitLab issuing the ID token and AWS accepting it for the role, with the trust policy conditions on
audandsub. - Not verified against GitLab:
image,timeout,expire_inandcache(gitlab-ci-local ignores them). - Not verified against a GitLab pipeline schedule: the local run set the pipeline source by hand.
- Not verified against AWS: the OIDC role assuming the
InvenTagReadOnlyrole in each account, with real trust policies.
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: valuepairs; - 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,.yamlor.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).