Must provide an explicit region in the builder or setup environment to supply a region


I tried setting up a user like this:

and activate it via:

However, I keep getting the following exception:

May 20, 2018 3:09:02 PM com.amazonaws.auth.profile.internal.BasicProfileConfigLoader loadProfiles

WARNING: The legacy profile format requires the ‘profile ‘ prefix before the profile name. The latest code does not require such prefix, and will consider it as part of the profile name. Please remove the prefix if you are seeing this warning.

Exception in thread “main” com.amazonaws.SdkClientException: Unable to find a region via the region provider chain. Must provide an explicit region in the builder or setup environment to supply a region.

It is strange that if I configure it with the default user, then everything is working fine:

Why isn’t configuration with a specific username doesn’t work above?

I also know that we can configure the credential in code like this SO or this SO.

That works, but I just think it is a bad idea to put credentials in source code and check them in with git.

Also from the error message, it looks like I am using an old format with profile in the prefix name (as described in this SO. I’ve double checked the aws-cli version and make sure that it is up-to-date also double checked that I don’t have the prefix in the profile name.

Here is about the version:

And here is the configuration file:


Just figure out what’s wrong. There are two files generated with aws configure --profile MyUser.

  • ~/.aws/config
  • ~/.aws/credential

I notice that the generated config file does have profile in the prefix

After removing that, things work perfectly:

Alternatively, we can specify the credential configuration file and the user explicitly. As an example, in Scala:

Leave a Reply