No RegionEndpoint or ServiceURL configured

I was setting up Amazon SQS client locally, and received No RegionEndpoint or ServiceURL configured exception. My goal was to load all AWS config values from environment variables together with a temporary session token, however I will go trough config file option as well. Apparently region value was not picked up by the Amazon SQS client.

About No RegionEndpoint issue …

After a quick Google research seems like the issue has already been fixed, and I was using the correct SDK version. However, since I was still getting the exception, I decided to play with the AWS SQS client setup a little bit more. Let’s start with config file.

Config file

First, install AWS CLI (I used Windows 64-bit installer), open command prompt, and run the command below.

aws configure

And provide your configuration values to create config and credentials files in your user workspace, e.g. C:\Users\ignas\.aws. Please note I am using fake access key and secret just to illustrate this issue locally.


Next, create a new .NET Core console application (I am using Visual Studio Code), install AWS SQS SDK nuget package, and use the following code.

public class Program
    public static void Main(string[] args)
        var sqsClient = new AmazonSQSClient();
        Console.WriteLine("Hello World!");

Run the application and you will receive the exception.

Unhandled Exception: Amazon.Runtime.AmazonClientException: No RegionEndpoint or ServiceURL configured at Amazon.Runtime.ClientConfig.Validate() in E:\JenkinsWorkspaces\v3-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\ClientConfig.cs:line 451 at Amazon.Runtime.AmazonServiceClient..ctor(AWSCredentials credentials, ClientConfig config) in E:\JenkinsWorkspaces\v3-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\AmazonServiceClient.cs:line 152

At this point AmazonSQSClient tries to read local text file config, and can’t find neither region or service URL set. Having one of these values enables the SQS Client to connect to a messages queue. Hardcoding value or reading value from an appsettings config file and manually assigning to the client in your code would solve the problem, however there are more elegant ways.

Open credentials file (e.g. C:\Users\ignas\.aws\credentials) and add region value. Now the credentials file should look like following.

aws_access_key_id = id
aws_secret_access_key = key
region = eu-west-2

Run the application again, and you will see Hello World! — the exception is gone. Nicely done!

Environment variables

If you use environment variables, this exception could be solved in a similar way. To replicate the issue again, let’s delete the .aws folder, and run the application again. You should get 3 exceptions:

  1. Amazon.Runtime.AmazonClientException: Unable to find the ‘default’ profile in CredentialProfileStoreChain.
  2. System.InvalidOperationException: The environment variables AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN were not set with AWS credentials.
  3. System.Net.Http.HttpRequestException: An error occurred while sending the request. —> System.Net.Http.WinHttpException: The operation timed out

Let’s follow the exception #2 and use environment variables to store config values. In the command prompt, run following commands (using fake values again).

setx AWS_SESSION_TOKEN "token"

To confirm the variables run set command to list all the user environment variables. See screenshot below.


However, the variables are not there! The key point is to close and re-open the command prompt to force it to re-load the latest environment variables.

If you run the application now, you will get the same 3 exceptions again, since you also need to restart Visual Studio Code or Visual Studio!

After restarting Visual Studio Code, we are back in the square one with No RegionEndpoint or ServiceURL configured exception. To add region to environment variables, run the following command in the command prompt.

setx AWS_Region "eu-west-2"

To verify in the command prompt, close and re-open the command prompt, and use set command just like mentioned above.

Region environment variable for RegionEndpoint issue

And also restart Visual Studio Code! Now, run the application, and you will see the Hello World! again. Nicely done again!

Tips & tricks

There are several ways to manage environment variables in Windows.

  • Using command prompt or a cmd emulator like Cmder.
  • Edit directly in registry.
Region environment variable for RegionEndpoint issue
  • Manage using Windows GUI. Search for Edit the system environment variables in Start menu, and click the Environment Variables button.
Region environment variable for RegionEndpoint issue


Applications load environment variables on startup and do not refresh them, hence an application restart is needed to pick up changes to environment variables. This applies to all environment variables, not only AWS ones, and all applications, not only command prompt window. Make sure to restart Visual Studio Code, Visual Studio, or the application itself if launched directly.