Wed Sep 15 2021·2 min read
Photo by Chad Madden
The reason the "Could not connect to the endpoint URL" error occurs is because an incorrect region code is set when executing the CLI command.
In order to solve the "Could not connect to the endpoint URL" error we have to set the region to a valid AWS region code:
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 executing 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 execute 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
I'll send you 1 email a week with links to all of the articles I've written that week