Borislav Hadzhiev
Reading time·2 min
Photo from Unsplash
The "Invalid endpoint" error occurs when the region that applies to the AWS CLI command is not set properly and most often is set to an empty string:
To solve the "Invalid endpoint" error set the --region
parameter to a valid
region code when executing the command:
aws ec2 describe-instances --region us-east-1
To view all the available region codes, check out the
AWS Region Availability List
and look at the Region
column.
The region we specify is used when composing the URL for the API request (the endpoint), therefore if we get the region code incorrect the whole endpoint becomes invalid.
To specify a region that applies to all commands executed by an AWS CLI
profile we can use the aws configure set region
command:
# configure the region for the john profile aws configure set region us-east-1 --profile john # configure the region for the default profile aws configure set region us-west-1 --profile default
In the code sample, we set the region for the AWS profile john
to us-east-1
.
This means that any time this profile executes a CLI command without passing the
--region
parameter, the AWS CLI uses the configured region. For example:
# use the john profile aws ec2 describe-instances --profile john # use the default profile aws ec2 describe-instances
The setting for the region is stored in the following files:
~/.aws/config
C:\Users\USERNAME\.aws\config
There are 2 ways to override the region that's set in your config file:
--region=another-region
parameter when executing the commandAWS_DEFAULT_REGION
environment variable in your shell. The
AWS_DEFAULT_REGION
environment variable has higher precedence than the
specified region in your config file, but gets overridden when the --region
parameter is passed.aws configure set region
command to set the most commonly used region for a profile and then override it by passing the --region
parameter for one-off commands.