# How to check which AWS account the CLI is using

How-to guides · Updated 16 November 2026

**Short answer:** Run aws sts get-caller-identity. It returns the account ID, the ARN of the IAM user or assumed role, and a user ID, and it needs no IAM permissions, so it works with any valid credentials. aws configure list shows where those credentials and the Region came from (environment variables, a profile, SSO), which is what you need when the answer is not the account you expected.

## The two commands

```
aws sts get-caller-identity
# {
#   "UserId": "AROAEXAMPLEID123456:alex@example.com",
#   "Account": "123456789012",
#   "Arn": "arn:aws:sts::123456789012:assumed-role/AWSReservedSSO_Developer_0a1b2c3d4e5f6789/alex@example.com"
# }

aws configure list
#       Name                    Value             Type    Location
#       ----                    -----             ----    --------
#    profile                 acme-dev           manual    --profile
# access_key     ****************WXYZ              sso
# secret_key     ****************abcd              sso
#     region                eu-west-2      config-file    ~/.aws/config
```

Add `--profile name` to either command to check a specific profile. To show the account's friendly name, `aws iam list-account-aliases` returns the alias if one is set (and if you're allowed to call it).

## Reading the ARN

| ARN looks like | You are |
|---|---|
| `arn:aws:iam::123456789012:user/alex` | An IAM user with long-term access keys |
| `arn:aws:sts::123456789012:assumed-role/Admin/session-name` | A role session (from `assume-role`, a role profile, EC2, ECS or Lambda) |
| `…assumed-role/AWSReservedSSO_PermissionSet_…/alex@example.com` | An IAM Identity Center (SSO) sign-in |
| `arn:aws:iam::123456789012:root` | The root user. Stop and use something else; root shouldn't have access keys. |

The `UserId` field helps too: for a role session it is the role's unique ID followed by the session name, the same value CloudTrail records for that session's calls.

## "How do I change it?"

You don't change what `get-caller-identity` says; you change which credentials the CLI picks up. In order of precedence:

1. `--profile` on the command line.
2. `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN` in the environment. Leftovers here are the most common reason for "wrong account": `unset` them.
3. `AWS_PROFILE`.
4. The `[default]` profile, then instance or container roles.

See [switching profiles](https://cloudconsole.dev/how-to/switch-between-aws-profiles) and [assuming a role](https://cloudconsole.dev/how-to/switch-role-aws-cli).

## When get-caller-identity itself fails

| Error | Meaning |
|---|---|
| [The security token included in the request is invalid](https://cloudconsole.dev/errors/security-token-included-in-the-request-is-invalid) | Credentials are malformed or revoked, or a session token is missing or belongs to other keys |
| [ExpiredToken](https://cloudconsole.dev/errors/expiredtoken) | Temporary credentials have expired; log in or assume the role again |
| [InvalidClientTokenId](https://cloudconsole.dev/errors/invalidclienttokenid) | The access key ID doesn't exist (deleted, or from another partition) |
| [Unable to locate credentials](https://cloudconsole.dev/errors/unable-to-locate-credentials) | No credentials found anywhere in the chain |
| [SSO token expired](https://cloudconsole.dev/errors/sso-token-expired-refresh-failed) | Run `aws sso login` |

Because the call needs no permissions, an `AccessDenied` on anything else combined with a successful `get-caller-identity` tells you the credentials are fine and the problem is policy.

## Habits that prevent wrong-account mistakes

- Run `get-caller-identity` at the start of any script that changes things, and abort if `Account` isn't the expected ID.
- Show the active profile in your shell prompt.
- Give production profiles obviously different names and, ideally, read-only defaults.
- A successful call proves the credentials are valid now. Temporary credentials can still expire halfway through a long job, so long-running scripts should handle `ExpiredToken` and re-authenticate.

## Questions

### Does aws sts get-caller-identity need permissions?

No. Any valid credentials can call it, even if a policy denies everything else, so it is the safest test of which identity you are using.

### How do I find my AWS account ID from the CLI?

aws sts get-caller-identity --query Account --output text prints just the 12-digit account ID.

### Why does get-caller-identity show a different account from the console?

The CLI uses its own credentials chain (profile, environment variables, SSO cache) independent of the browser session. Check aws configure list to see what it is using.

## When this happens away from your desk

Knowing which account you are in matters even more on a small screen. CloudConsole, a phone app for AWS, is built to keep the account and role visible on every screen, with production guardrails.

[About the CloudConsole app](https://cloudconsole.dev/aws-console-app) · [Download on the App Store](https://apps.apple.com/app/cloudconsole-for-aws/id6835419710)

## Sources

- [GetCallerIdentity API reference](https://docs.aws.amazon.com/STS/latest/APIReference/API_GetCallerIdentity.html)
- [Configuration and credential file settings in the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html)

## Related

- [aws sts get-caller-identity](https://cloudconsole.dev/cli/sts-get-caller-identity)
- [The security token included in the request is invalid](https://cloudconsole.dev/errors/security-token-included-in-the-request-is-invalid)
- [How to switch between AWS profiles](https://cloudconsole.dev/how-to/switch-between-aws-profiles)
- [aws configure list-profiles](https://cloudconsole.dev/cli/configure-list-profiles)
- [Unable to locate credentials](https://cloudconsole.dev/errors/unable-to-locate-credentials)
- [How to switch role with the AWS CLI](https://cloudconsole.dev/how-to/switch-role-aws-cli)

---

Source: https://cloudconsole.dev/how-to/check-who-is-logged-in-aws-cli

CloudConsole is an independent iPhone and Android app for Amazon Web Services by Cloudconcur Ltd. It is not affiliated with Amazon Web Services.
