Last updated: Feb 26, 2024
Reading time·3 min
The reason the "Could not connect to the endpoint URL" error occurs is because an incorrect region code is set when running an AWS CLI command.
In order to solve the "Could not connect to the endpoint URL" error, set the
region to a valid AWS region code, e.g. us-east-1
.
aws ec2 describe-instances --region us-east-1
To view all the valid region codes, check out the
Available AWS Regions
table and look at the Region
column.
There are multiple ways to set the region that applies to a CLI command.
In order of precedence:
--region=us-east-1
parameter when running the command. This
approach has the highest precedence and overrides the other 2. However, you
have to pass the parameter with every command.AWS_DEFAULT_REGION
environment variable. This approach often
leads to confusion. It has a lower precedence than the --region
parameter
but overrides the region setting in the AWS config file.--region
parameter and the AWS_DEFAULT_REGION
environment variable are not set.--region
parameter when needed.To update the region of an AWS CLI profile, run the aws configure set region
command.
# Update the region of the profile john aws configure set region us-east-1 --profile john # Update the region of the default profile aws configure set region us-west-1 --profile default
The aws configure set region
command updates the setting in the following
file:
~/.aws/config
C:\Users\YOUR_USERNAME\.aws\config
Having set a correct AWS region code for a profile in your config file means
that the next time you run a command for that profile and don't pass the
--region
parameter, the AWS CLI will look up the region value in your config
file (assuming the AWS_DEFAULT_REGION
variable is not set on your machine).
# Uses the region configured for the john profile aws ec2 describe-instances --profile john # Uses the region configured for the default profile aws ec2 describe-instances
You can learn more about the related topics by checking out the following tutorials: