Sub topic 15
Troubleshooting common errors
This chapter assumes you can run AWS CLI v2 commands, have at least one named profile, and know that most resources belong to a single Region. Most CLI and Console problems come from three causes: the wrong identity, the wrong Region, or missing permissions. Check them in that order.
A diagnostic order
Start with these commands:
aws configure list-profiles
aws configure list --profile dev
aws sts get-caller-identity --profile devaws configure list shows where each value came from, such as an environment variable, a config file, or a profile. get-caller-identity shows the account and the ARN that AWS sees. It needs no IAM permissions, so it works whenever your credentials are valid.
Identity errors
| Message | Likely cause | Fix |
|---|---|---|
| Unable to locate credentials | No profile, key, or role is configured | Run `aws configure`, or pass `--profile` |
| The config profile (dev) could not be found | Profile name is misspelled or missing | Compare with `aws configure list-profiles` |
| ExpiredToken, or the security token is expired | Temporary credentials have timed out | Run `aws sso login --profile dev` |
| InvalidClientTokenId | The access key is wrong, deleted, or deactivated | Check the key in IAM, or switch to SSO |
| Error loading SSO Token | The SSO session is missing or expired | Run `aws sso login` again |
Environment variables override the config files. A stale AWS_ACCESS_KEY_ID or AWS_PROFILE left in your shell can make the CLI use an identity you did not intend. aws configure list reveals this, and unset removes the variable.
Region errors
A missing Region produces "You must specify a region". A wrong Region is harder to spot because the command succeeds and returns empty results. Your instances seem to have vanished, but they are in another Region.
aws configure get region --profile dev
aws ec2 describe-instances --region eu-west-1 --profile dev \
--query 'Reservations[].Instances[].InstanceId' --output textThe Console works the same way. Check the Region selector in the top bar before you assume a resource is gone. Global services such as IAM ignore the Region, so do not treat a service that appears to ignore it as a bug.
Permission errors
AccessDenied, UnauthorizedOperation, and "not authorized to perform" all mean AWS recognized you and refused the action. The message names the action and the resource. Read it, then compare it with the policies attached to the identity that get-caller-identity returned.
aws s3api list-buckets --profile devWith the ReadOnly role from the earlier profile example, a write call such as create-bucket fails by design. The fix is to use a role with the right permissions. Do not switch to the root user.
Other common causes are a service control policy, a permissions boundary, or a resource policy that denies access. Your own policy may be fine in those cases.
Other quick checks
- Add
--debugto see which credentials source and endpoint the CLI used. - Run
aws --versionto confirm you are on v2. An older v1 install earlier on your PATH is a common surprise. - A system clock that is off by several minutes causes signature errors.
Exercise
aws ec2 describe-instances succeeds but returns an empty list, although you launched an instance an hour ago. Which two checks do you run first, and why?
Show answer
Run aws sts get-caller-identity to confirm you are in the intended account, then check the Region with aws configure get region or by passing --region. A command with valid credentials returns an empty result, not an error, when the instance is in a different account or Region.