AWS CLI executing in wrong regions

2019-08-28 00:27发布

问题:

My AWS profile is configured to default to eu-west-1, however when I run an AWS CLI command, it is executing in us-east-1:

>aws configure get region
eu-west-1

>aws events put-rule --name hourly_trigger --schedule-expression "rate(60 minutes)"
{ 
  "RuleArn": "arn:aws:events:us-east-1:588237033746:rule/hourly_trigger"
}

I've looked into profiles and config options and can't determine why this is. My profile is set as follows:

[default]
region = eu-west-1

And this command works in the intended region if I add --region

>aws events put-rule --name hourly_trigger --schedule-expression "rate(60 mi
nutes)" --region eu-west-1
{
    "RuleArn": "arn:aws:events:eu-west-1:588237033746:rule/hourly_trigger"
}

回答1:

AWS Region is obtained through three ways:

  1. Checks if your command contains --region
  2. If not specified, Checks the env variable AWS_DEFAULT_REGION
  3. If that is not set, it checks the region defined in the ~/.aws/config file

Make sure AWS_DEFAULT_REGION is not set. Then it should automatically use the region defined in the config file.