Solve - Invalid Endpoint Error in AWS CLI

avatar

Borislav Hadzhiev

Wed Sep 15 20212 min read

banner

Photo by Ivana Cajina

Solving AWS CLI Invalid Endpoint error #

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:

invalid endpoint error

To solve the "Invalid endpoint" error set the --region parameter to a valid region code when executing the command:

shell
aws ec2 describe-instances --region us-east-1

region parameter set

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:

shell
# 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 snippet we've 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:

shell
# 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:

  • on linux and macOS: ~/.aws/config

aws cli config file

  • on windows: C:\Users\USERNAME\.aws\config

There are 2 ways to override the region that's set in your config file:

  1. Pass the --region=another-region parameter when executing the command
  2. Set the AWS_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.
The environment variable approach introduces confusion and should be avoided. It's best to use the 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.

Further Reading #

Add me on LinkedIn

I'm a Web Developer with TypeScript, React.js, Node.js and AWS experience.

Let's connect on LinkedIn

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee