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.
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
There are multiple ways to set the region that applies to a CLI command.
In order of precedence:
--region=us-east-1parameter 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_REGIONenvironment variable. This approach often leads to confusion. It has lower precedence than the
--regionparameter but overrides the region setting in the AWS config file.
--regionparameter and the
AWS_DEFAULT_REGIONenvironment variable are not set.
--regionparameter when needed.
To update the region of an AWS CLI profile, run the
aws configure set region
# 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
aws configure set region command updates the setting in the following
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: