Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

AWS CLI says you must specify a region

ErrorYou 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.

  • Applies to AWS CLI 2, Ubuntu 24.04, macOS 15
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print what the CLI resolves for region, and where each value comes from.

    aws configure list
  2. 2Match what you see, then jump to its fix

    1. 1aws configure list shows region as <not set>The default profile has no regionFix
    2. 2It works with --profile admin but not without it, or the other way roundYou are using another profile that lacks a regionFix
    3. 3Works on your laptop, fails in CI, cron or a fresh containerA script or container has no config files at allFix
    4. 4You configured us-east-1 but requests go to, or fail for, another regionA variable or flag overrides the region you setFix

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/config

2Fix

Store a region in the profile. Use the region where your resources live.

aws configure set region us-east-1

3Verify

The value now shows up as coming from the config file.

aws configure list

Confirmed by docs.aws.amazon.com

Did this fix it?

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-profiles

2Fix

Set the region on the profile you actually use, naming it explicitly.

aws configure set region us-west-2 --profile integ

3Verify

Read the value back for that profile.

aws configure get region --profile integ

Confirmed by docs.aws.amazon.com

Did this fix it?

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-2

3Verify

Check that the region now resolves from the environment.

aws configure list

Confirmed by docs.aws.amazon.com

Did this fix it?

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-1

3Verify

aws configure list shows the region and its source.

aws configure list

Confirmed by docs.aws.amazon.com

Did this fix it?

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:

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 fix

Servers

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.