Some examples in internet have AWS_DEFAULT_REGION
env variable set but some others AWS_REGION
. What is the difference? Which services use one or another?

- 31,309
- 66
- 224
- 364
-
Both are same, they have updated env variable to `AWS_DEFAULT_REGION`, here is the documentation https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html – Ahmet Zeybek Jan 29 '20 at 07:11
6 Answers
They are not the same: one works in some situations and the other works in other situations.
e.g. I just learned that AWS_DEFAULT_REGION
does not work with the AWS Java API library. See Force AWS library to obtain region from environment inside docker cluster

- 11,804
- 7
- 44
- 52
-
2AWS_DEFAULT_REGION works in python boto3 and the cdk. AWS_REGION doesn't work for boto, cdk. The name kind of make you think they would complement each other but that's isn't true. For python it's this and java it's that while people work in multiple languages at a time. Such a mess. – Khoa Aug 12 '21 at 00:48
AWS_REGION
is the new/preferred. All SDKs use AWS_REGION
except boto3 and AWS CLIv1 Compatibility between SDKs page in Amazon official documentation.
Unfortunately, boto3 will not add AWS_REGION
until the next major release (see this comment)
boto3 and the AWS CLI v1 are exceptions in that they use AWS_DEFAULT_REGION. It was called out in the v2 migration changes page that AWS_REGION was added for v2. It is an unfortunate inconsistency between the SDKs but as you suggested, it would be a breaking change to adjust the credential precedence at this point, and so I don't think this could be considered until the next major version of the SDK.
The AWS CLI supports both AWS_REGION
and AWS_DEFAULT_REGION
and in the context of the CLI they are the same (AWS_REGION
takes precedence if set) . See Environment variables to configure the AWS CLI. AWS CLI v1 used AWS_DEFAULT_REGION
only and in AWS CLI v2 they introduced AWS_REGION
see aws cli v2 migration notes.
So in general we could say that you better set both AWS_REGION
and AWS_DEFAULT_REGION
to the same value if you want to be sure (like if you don't know what SDK was used to build the application). Otherwise you need to use
- AWS_DEFAULT_REGION
- AWS CLIv1
- Python SDK boto3
- AWS_REGION
- AWS CLIv2
- Go SDK
- Javascript SDK
- Java SDK
- all other SDKs in general

- 21,435
- 13
- 113
- 151
I have learned, the hard way, that they're not the same. Depending on what SDK you use (or cli) read the config documentation for that specific SDK. Certain SDKs (e.g. Golang) uses AWS_REGION
, while others obey AWS_DEFAULT_REGION
. This is not a precedence issue, in Go, it doesn't even care about AWS_DEFAULT_REGION
.

- 984
- 6
- 20
The AWS_DEFAULT_REGION environment variable belongs to awscli. AWS_REGION is recognized/respected by a number of other projects/platforms.
Namespacing environment variables is hard/important.

- 674
- 7
- 7
AWS_REGION
The AWS SDK compatible environment variable that specifies the AWS Region to send the request to.
If defined, this environment variable overrides the values in the environment variable AWS_DEFAULT_REGION and the profile setting region. You can override this environment variable by using the --region command line parameter.
source : https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html

- 503
- 4
- 14
AWS_DEFAULT_REGION
and AWS_REGION
is the same.
They first introduce AWS_REGION
in SDK and then AWS_DEFAULT_REGION
comes later.
it is also asked in their aws-cli
AWS_DEFAULT_REGION - Specifies the AWS Region to send the request to. If defined, this environment variable overrides the value for the profile setting region. You can override this environment variable by using the --region command line parameter. source

- 102
- 3
-
1Sure, conceptually they are the same (just region names). But, depending on the SDK, you might use one over the other. – saedx1 Aug 25 '21 at 12:20