mattgillard / aws-whoami

A tool to show what AWS account and identity you're using.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 you're configured to use, 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.

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

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.

Other uses

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

If you want to use it as a library, the whoami() function, which optionally takes a boto3.Session, returns a WhoamiInfo namedtuple.

About

A tool to show what AWS account and identity you're using.

License:Apache License 2.0


Languages

Language:Python 100.0%