FG
☁️ Cloud & DevOpsAmazon

aws-cli should set default region to EC2 instance region

Freshabout 6 years ago
Mar 14, 20260 views
Confidence Score87%
87%

Problem

Recently we provisioned an EC2 instance with the aws-cli installed that is using IAM roles. We forgot to set the AWS_DEFAULT_REGION environment variable and got an error stating that the default region was not specified. I am proposing that aws-cli should be able to assume the given region of the EC2 instance. This would eliminate one step of adding the environment variable to the system. If the aws-cli needs to talk to a different region, it can always use a different profile or override the region. I am sure there are implications to this that need to be thought about.

Error Output

error stating that the default region was not specified.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate2 verificationsLast verified Mar 14, 2026

Solution: aws-cli should set default region to EC2 instance region

Low Risk

As @jamesls has found, we can get the region itself from the instance metadata: [code block] So, we can discover the region in which an EC2 instance is running quickly and efficiently. If a customer ran `aws configure` on an EC2 instance, it would seem reasonably to offer the region in which they are currently running as the default value to place in their config file. I think this makes a lot

84

Trust Score

2 verifications

100% success
  1. 1

    As @jamesls has found, we can get the region itself from the instance metadata:

    As @jamesls has found, we can get the region itself from the instance metadata:

    text
    $ curl http://169.254.169.254/latest/dynamic/instance-identity/document
    {
      "version" : "2010-08-31",
      "architecture" : "x86_64",
      "instanceType" : "t1.micro",
      ...
      "region" : "us-west-2",
      "availabilityZone" : "us-west-2b",
      ...
    }
  2. 2

    So, we can discover the region in which an EC2 instance is running quickly and e

    So, we can discover the region in which an EC2 instance is running quickly and efficiently.

  3. 3

    If a customer ran `aws configure` on an EC2 instance, it would seem reasonably t

    If a customer ran `aws configure` on an EC2 instance, it would seem reasonably to offer the region in which they are currently running as the default value to place in their config file. I think this makes a lot of sense.

  4. 4

    However, what if they are using an IAM Role rather than traditional credentials.

    However, what if they are using an IAM Role rather than traditional credentials. In this case they probably wouldn't run `aws configure`. Should we still just automatically assume that they want to use the region of the instance as the default region? I'm not so sure about that. Sometimes it will be exactly what they want and in other situations it may be confusing.

Validation

Resolved in aws/aws-cli GitHub issue #486. Community reactions: 1 upvotes.

Verification Summary

Worked: 2
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

awsclicloudfeature-requestv2