AWS CLI says you must specify a region
You must specify a region. You can also configure your region by running "aws configure".Short answer
The AWS CLI sends every request to one region and has none to use. Give it one for a single command with --region, for all commands with aws configure set region, or through an environment variable. If one is set and still ignored, a different profile or a higher-priority variable is in play.
Fix it fast
1Find out which cause you have
Print what the CLI resolves for region, and where each value comes from.
aws configure list2Match what you see, then jump to its fix
- 1
aws configure list shows region as <not set>The default profile has no regionFix - 2
It works with --profile admin but not without it, or the other way roundYou are using another profile that lacks a regionFix - 3
Works on your laptop, fails in CI, cron or a fresh containerA script or container has no config files at allFix - 4
You configured us-east-1 but requests go to, or fail for, another regionA variable or flag overrides the region you setFix
- 1
What does the error look like?
You must specify a region. You can also configure your region by running "aws configure".
Cause 1 of 4
The default profile has no region
1Check
The CLI uses the profile named default unless told otherwise. If that profile has no region line, nothing else fills the gap.
cat ~/.aws/config2Fix
Store a region in the profile. Use the region where your resources live.
aws configure set region us-east-13Verify
The value now shows up as coming from the config file.
aws configure listConfirmed by docs.aws.amazon.com
Cause 2 of 4
You are using another profile that lacks a region
1Check
Each profile carries its own settings. A region saved under one profile is not used by another.
echo "$AWS_PROFILE"
aws configure list-profiles2Fix
Set the region on the profile you actually use, naming it explicitly.
aws configure set region us-west-2 --profile integ3Verify
Read the value back for that profile.
aws configure get region --profile integConfirmed by docs.aws.amazon.com
Cause 3 of 4
A script or container has no config files at all
1Check
Those environments have no ~/.aws/config. Environment variables are the usual way to give them settings.
env | grep '^AWS_'2Fix
Export a region for the job. AWS_REGION and AWS_DEFAULT_REGION both work, and AWS_REGION wins if both are set.
export AWS_DEFAULT_REGION=us-west-23Verify
Check that the region now resolves from the environment.
aws configure listConfirmed by docs.aws.amazon.com
Cause 4 of 4
A variable or flag overrides the region you set
1Check
A command-line --region beats environment variables, and environment variables beat the profile. A leftover AWS_REGION in your shell hides the config file.
aws configure list
env | grep -E '^AWS_(DEFAULT_)?REGION'2Fix
Unset the stray variable, or pass the region you mean on the command.
unset AWS_REGION AWS_DEFAULT_REGION
aws ec2 describe-instances --region eu-west-13Verify
aws configure list shows the region and its source.
aws configure listConfirmed by docs.aws.amazon.com
How do I stop it coming back?
- Set a region when you first run aws configure, and name the region in scripts with --region.
- Keep one profile per account and set the region on each.
- In CI, set AWS_DEFAULT_REGION in the job definition, not on the runner image.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
- Loade DriverThe driver side of a delivery platform: live jobs, routing and earnings, past 5K Google Play downloads.
Related fixes
Servers
Apache has a certificate, but https:// does not open
No line with :443 in the output of ss -ltnp
HTTPS needs four things at once: mod_ssl loaded, Apache listening on 443, a virtual host on 443 with SSLEngine on, and a firewall that lets 443 in.
4 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
git clone from CodeCommit over HTTPS returns 403
aws codecommit credential-helper $@ get: aws: command not found
A 403 from CodeCommit over HTTPS usually means Git sent the wrong credentials, not none.
5 causes, each with a fixServers
EC2 Instance Connect from the browser will not open an SSH session
Host key validation failed for EC2 Instance Connect
Browser-based EC2 Instance Connect needs five things at once: a fresh host key in the AWS database, a current agent package, port 22 open to the EC2 Instance Connect prefix list, a public address with a route (or an Instance Connect Endpoint), and a browser that can reach the proxy on port 443.
5 causes, each with a fixServers
EC2 instance shows 'Instance reachability check failed' and will not answer
Out of memory: kill process
A failed instance reachability check means the operating system inside the instance is not responding, so the problem is yours to fix, not AWS hardware.
4 causes, each with a fixServers
ssh to an EC2 instance hangs and ends in Connection timed out
Network error: Connection timed out
A timeout means your packets never got an answer, so this is a network path problem, not a key problem.
4 causes, each with a fix