← All cheatsheets

Cloud

AWS CLI — auth, context, and everyday operations

Everyday aws CLI reference: authenticate (SSO/profiles), confirm WHO you are and WHICH account/region is active, read and describe resources, tail logs, and run the handful of scoped create/deploy ops people actually touch. Confirm context with sts get-caller-identity before any write.

Docs-checkedawscliiamstss3ec2

Quick reference — reach for these first

Who am I? / what context?aws sts get-caller-identityPrints Account, Arn, UserId for the currently resolved credentials — run before any change
Refresh SSO loginaws sso login --profile PROFILERenews the short-lived IAM Identity Center token for that profile
Pick the active contextexport AWS_PROFILE=PROFILE AWS_REGION=REGIONSets profile + region for this shell; overrides config defaults
Safe read to prove accessaws s3 lsLists buckets — fast check that creds and region actually work
Tail logs liveaws logs tail GROUP --follow --since 10mStreams a CloudWatch Logs group in real time

AWS CLI credential & context resolution (first match wins)

AWS CLI credential and context resolution orderFour credential sources checked in precedence order, confirmed with sts get-caller-identity.Resolution order — first match wins1 CLI flags: --profile / --region / keyshighest priority, per-command2 Env: AWS_PROFILE, AWS_ACCESS_KEY_ID, AWS_REGIONper-shell3 Shared files: ~/.aws/config, credentials+ SSO token cache4 IMDS: EC2 / container instance rolefallback on AWS computefirst match winsConfirm the winneraws sts get-caller-identity→ Account (ACCOUNT_ID)→ Arn, UserIdNo region in 1–3 and not on EC2 → error: "You must specify a region".

Text equivalent: A vertical stack of four credential sources the AWS CLI checks in order, top to bottom: 1 CLI flags such as --profile and --region; 2 environment variables AWS_PROFILE, AWS_ACCESS_KEY_ID, AWS_REGION; 3 shared files ~/.aws/config and credentials plus the SSO cache; 4 EC2/container instance role via IMDS. An arrow down the left is labeled 'first match wins'. A box on the right says: confirm the winner with aws sts get-caller-identity, which returns Account, Arn, and UserId. A note at the bottom warns that if no region is set in sources 1 to 3 and you are not on EC2, the CLI errors 'You must specify a region'.

Common tasks

Task · Command · What to check

TaskCommandWhat to check
Configure an SSO (Identity Center) profileaws configure sso~/.aws/config gains [profile PROFILE] with an sso_session block
Log in / refresh the SSO tokenaws sso login --profile PROFILE"Successfully logged into Start URL"; sts call below then succeeds
Confirm identity + account (do this first)aws sts get-caller-identity --profile PROFILEAccount equals the expected ACCOUNT_ID and Arn is the role you meant
Set default profile + region for the shellexport AWS_PROFILE=PROFILE AWS_REGION=REGIONaws configure list shows profile/region sourced from 'env'
List configured profilesaws configure list-profilesThe profile you expect appears in the output
Persist a region on a profileaws configure set region REGION --profile PROFILEaws configure get region --profile PROFILE returns REGION
List S3 buckets / a bucket's objectsaws s3 ls # aws s3 ls s3://BUCKET/Expected buckets/keys returned; no AccessDenied
Describe EC2 instances in the regionaws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId,State.Name]' --output tableInstances for REGION listed with state
Tail a CloudWatch Logs groupaws logs tail GROUP --follow --since 15mLive log events stream to the terminal
List ECS services in a clusteraws ecs list-services --cluster CLUSTERService ARNs returned for CLUSTER
Deploy an ECS service [LABEL: billable / prod]aws ecs update-service --cluster CLUSTER --service SERVICE --force-new-deploymentdescribe-services shows a new deployment PRIMARY rolling out
Wire kubectl to an EKS clusteraws eks update-kubeconfig --name CLUSTER --region REGIONkubectl get ns succeeds against the right cluster
Inspect IAM roles/user for the principalaws iam list-roles --query 'Roles[].RoleName' # aws iam get-userExpected roles listed (no AccessDenied)
Stop one instance, scoped [LABEL: destructive]aws ec2 stop-instances --instance-ids INSTANCE_IDCurrentState transitions to 'stopping' for only that INSTANCE_ID

From zero: authenticate, CONFIRM context, one safe read, one scoped write, verify

auth → confirm → read → scoped write → verify

1
Authenticate to the account via SSO
aws sso login --profile PROFILE
# Successfully logged into Start URL: https://d-xxxx.awsapps.com/start
2
Make this the active context for the shell
export AWS_PROFILE=PROFILE AWS_REGION=REGION
3
CONFIRM who/where before touching anything
aws sts get-caller-identity
# {
#   "Account": "ACCOUNT_ID",
#   "Arn": "arn:aws:sts::ACCOUNT_ID:assumed-role/AWSReservedSSO_Admin/you"
# }
4
Safe read to prove creds + region work
aws s3 ls
# 2026-01-02 09:14:31 my-app-logs
5
Small scoped write: tag exactly one instance
aws ec2 create-tags --resources INSTANCE_ID --tags Key=Owner,Value=me
✓
Verify the write landed on that instance only
aws ec2 describe-instances --instance-ids INSTANCE_ID --query 'Reservations[].Instances[].Tags'
# [[{"Key":"Owner","Value":"me"}]]
!
If step 3 shows the wrong ACCOUNT_ID, STOP — fix AWS_PROFILE before any write; the CLI silently acts on whatever context resolved.

Troubleshooting — symptom → first check → next check

SymptomFirst checkEstablishesNext check
AccessDenied / not authorized to performaws sts get-caller-identityWhich principal (Arn) the CLI is actually usingConfirm the Arn's IAM policy grants the action, or switch --profile/role; re-run
ExpiredToken / the security token has expiredaws sts get-caller-identityCredentials expired vs. genuinely wrong principalaws sso login --profile PROFILE (or rotate static keys), then retry
Wrong account/project — expected resources are missingaws sts get-caller-identity; echo $AWS_PROFILEWhich account/profile the CLI is pointed at right nowSet AWS_PROFILE or --profile to the intended account before acting
You must specify a regionaws configure get region; echo $AWS_REGIONNo region resolved from flags, env, or profileexport AWS_REGION=REGION, pass --region REGION, or configure set region
Throttling / Rate exceeded / TooManyRequestsRead the error code in the responseServer-side throttle rather than a client/auth errorLet built-in retries run, or set AWS_RETRY_MODE=adaptive and AWS_MAX_ATTEMPTS; back off / narrow the query
Could not connect to the endpoint URLVerify REGION and that the service exists thereBad region/endpoint vs. network or proxy blockCorrect --region, or check VPC egress / HTTP(S)_PROXY settings
Unable to locate credentialsaws configure listNothing resolved anywhere in the credential chainaws configure sso (or configure) to set up PROFILE, then sso login

References

AWS CLI v2 on macOS/Linux with IAM Identity Center (SSO) profiles; adjust for static IAM keys or CLI v1.

Related sheets