Skip to main content

aws-whoami

Show what AWS account and identity you're using

You should know about aws sts get-caller-identity, which sensibly returns the identity of the caller. But even with --output table, I find this a bit lacking. That ARN is a lot to visually parse, it doesn't tell you what region your credentials are configured for, and I am not very good at remembering AWS account numbers. aws-whoami makes it better.

$ aws-whoami
Account:         123456789012
                 my-account-alias
Region:          us-east-2
AssumedRole:     MY-ROLE
RoleSessionName: ben
UserId:          SOMEOPAQUEID:ben
Arn:             arn:aws:sts::123456789012:assumed-role/MY-ROLE/ben

Note: if you don't have permissions to iam:ListAccountAliases, your account alias won't appear. See below for disabling this check if getting a permission denied on this call raises flags in your organization.

Install

I recommend you install aws-whoami with pipx, which installs the tool in an isolated virtualenv while linking the script you need.

# with pipx
pipx install aws-whoami

# without pipx
python -m pip install --user aws-whoami

If you don't want to install it, the aws_whoami.py file can be used on its own, with only a dependency on botocore (which comes with boto3).

Options

aws-whoami uses boto3, so it'll pick up your credentials in the normal ways, including with the --profile parameter.

If you'd like the output as a JSON object, that's the --json flag. The output is the WhoamiInfo object (see below) as a JSON object.

To full disable account alias checking, set the environment variable AWS_WHOAMI_DISABLE_ACCOUNT_ALIAS to true. To selectively disable it, you can also set it to a comma-separated list of values that will be matched against the following:

  • The beginning or end of the account number
  • The principal Name or ARN
  • The role session name

As a library

The library has a whoami() function, which optionally takes a Session (either boto3 or botocore), and returns a WhoamiInfo namedtuple.

The fields of WhoamiInfo are:

  • Account
  • AccountAliases (NOTE: this is a list)
  • Arn
  • Type
  • Name
  • RoleSessionName
  • UserId
  • Region
  • SSOPermissionSet

Type, Name, and RoleSessionName (and SSOPermissionSet) are split from the ARN for convenience. RoleSessionName is None for IAM users.

SSOPermissionSet is set if the assumed role name conforms to the format AWSReservedSSO_{permission-set}_{random-tag}.

To disable the account alias check, pass disable_account_alias=True to whoami(). Note that the AccountAliases field will then be an empty list, not None.

format_whoami() takes a WhoamiInfo object and returns the formatted string used for display.

Metadata

Release files for aws-whoami 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-whoami 1.2.0
File Size Uploaded
aws-whoami-1.2.0.tar.gz 8.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aws-whoami 1.2.0
File Interpreter ABI Platform
aws_whoami-1.2.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 17.9 kB

Release files / aws-whoami-1.2.0.tar.gz

Download URL aws-whoami-1.2.0.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6b9de3a4cf6c3c5aa118a173c987d26916070273b677ef7cb30106403f862d18
BLAKE2b-256 checksum
How to use checksums
831227f6075ecbd893d12427858b3fe5242fb0c004c18248b65e6a58d5ff3a90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.8.3 Linux/4.19.128-microsoft-standard

Release files / aws_whoami-1.2.0-py2.py3-none-any.whl

Download URL aws_whoami-1.2.0-py2.py3-none-any.whl
Size 9.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
efec378716b3be074140c8623239cd2a0a708ffb8ae74d7486d0ee7b0b0feaa6
BLAKE2b-256 checksum
How to use checksums
b546caaf1c289cc8afd17d4c4d13046de34b94b96be9e2ab9abed4656745699f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.5 CPython/3.8.3 Linux/4.19.128-microsoft-standard

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page