AWS SDK for Java "Unable to Load Credentials From Any of the Providers in the Chain": The Fix for Local, Docker, EC2, ECS, EKS and SSO (and the AWS_DEFAULT_REGION Trap)
The AWS SDK for Java's "Unable to load credentials from any of the providers in the chain" means the SDK tried every place it knows to look for AWS keys, in order, and found nothing usable. The message is long, but the end of it lists every place it checked and why each one failed, and that list is the fastest way to the fix. Usually the fix is one of three things: set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, point AWS_PROFILE at a profile in ~/.aws/credentials, or give the EC2 instance, ECS task or EKS pod an IAM role. Two surprises catch Java developers in particular. First, the SDK's sister error, "Unable to load region from any of the providers in the chain", appears even when AWS_DEFAULT_REGION is set, because the Java SDK reads AWS_REGION, not the variable the AWS CLI uses. Second, an SSO profile that works perfectly in the CLI fails in Java until you add the SDK's sso module. This page decodes the message, then fixes each environment: your laptop, Docker, EC2, ECS, EKS, Lambda and SSO, for SDK v2 and the old v1.
Ethan, a developer, wrote a small Java service for his friend Jake's phone repair shop that reads the day's orders from AWS. It worked from his IDE. In a Docker container it failed with a wall of text about providers. He set AWS_DEFAULT_REGION, as he always did for the CLI, and got a second wall of text about regions. Both errors were telling him exactly what to do. He just hadn't read the last line.
New to AWS credentials? Every call your program makes to AWS is signed with a key pair, or with temporary keys from an IAM role. The SDK finds those keys for you by checking a fixed list of places, the credential provider chain. This page is about what happens when every place on the list comes up empty. Our guide to IAM covers users, roles and keys.
Decode the message: the chain and why each step failed
Here's the full error from SDK v2, from a program with no credentials anywhere. It starts with the list of providers the SDK tried:
software.amazon.awssdk.core.exception.SdkClientException: Unable to load credentials from any of the providers in the chain AwsCredentialsProviderChain(credentialsProviders=[SystemPropertyCredentialsProvider(), EnvironmentVariableCredentialsProvider(), WebIdentityTokenFileCredentialsProvider(), ProfileCredentialsProvider(...), ContainerCredentialsProvider(), InstanceProfileCredentialsProvider()])The useful part comes after it, in square brackets: one reason per provider, in the same order.
SystemPropertyCredentialsProvider(): Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId).
EnvironmentVariableCredentialsProvider(): Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId).
WebIdentityTokenFileCredentialsProvider(): Either the environment variable AWS_WEB_IDENTITY_TOKEN_FILE or the javaproperty aws.webIdentityTokenFile must be set.
ProfileCredentialsProvider(...): Profile file contained no credentials for profile 'default'
ContainerCredentialsProvider(): Cannot fetch credentials from container - neither AWS_CONTAINER_CREDENTIALS_FULL_URI or AWS_CONTAINER_CREDENTIALS_RELATIVE_URI environment variables are set.
InstanceProfileCredentialsProvider(): Failed to load credentials from IMDS.That's the whole chain, and the SDK stops at the first provider that works. Here's what each one looks for, and where it's normally used:
| Order | Provider | Looks for | Typical place |
|---|---|---|---|
| 1 | System properties | -Daws.accessKeyId, -Daws.secretAccessKey, -Daws.sessionToken | Quick tests, some app servers |
| 2 | Environment variables | AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN | Laptops, CI, Docker, Lambda |
| 3 | Web identity token | AWS_WEB_IDENTITY_TOKEN_FILE and AWS_ROLE_ARN | EKS (IAM roles for service accounts) |
| 4 | Profile | The default profile, or AWS_PROFILE, in ~/.aws/credentials and ~/.aws/config; also SSO, assumed roles and credential_process | Developer machines |
| 5 | Container | AWS_CONTAINER_CREDENTIALS_RELATIVE_URI or _FULL_URI | ECS tasks (the ECS agent sets it) |
| 6 | Instance profile | The EC2 instance metadata service (IMDS) | EC2 instances with an IAM role |
Read the reason for the provider you expected to work. If you thought you'd set environment variables, the second line proves the program can't see them. If you expected a profile, the fourth line names the profile it looked for and whether it found the file at all.
Jake: "So it's a checklist, and it tells you which box was empty."
Ethan: "All six boxes, in order. I'd been reading only the first line."
The region trap: AWS_REGION, not AWS_DEFAULT_REGION
Credentials aren't the only thing the SDK looks up in a chain. The region has its own, and its error looks almost the same:
software.amazon.awssdk.core.exception.SdkClientException: Unable to load region from any of the providers in the chain software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain@10dba097: [software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@6536e911: Unable to load region from system settings. Region must be specified either via environment variable (AWS_REGION) or system property (aws.region)., software.amazon.awssdk.regions.providers.AwsProfileRegionProvider@6c3708b3: No region provided in profile: default, ...Ethan got that with AWS_DEFAULT_REGION=us-east-1 set, because the Java SDK v2 doesn't read that variable. Its region chain checks, in order: a region set in code with .region(), the aws.region system property, the AWS_REGION environment variable, the region in your active profile, and finally the EC2 instance metadata service. AWS_DEFAULT_REGION, the variable many people set for the AWS CLI, isn't on that list. Any of these fixes it:
export AWS_REGION=us-east-1StsClient sts = StsClient.builder().region(Region.US_EAST_1).build();Or add region = us-east-1 to the profile in ~/.aws/config. On Lambda, there's nothing to do: Lambda sets AWS_REGION for you.
Jake: "So the AWS command line and the Java library don't even agree on the name of the setting?"
Ethan: "Not for the region. I set the CLI's one out of habit. The Java one has no 'DEFAULT' in it."
Fix it on your machine: environment variables, a profile, or system properties
On a laptop, the cleanest fix is a profile. Create one with the AWS CLI (aws configure --profile shop) or by hand in ~/.aws/credentials:
[shop]
aws_access_key_id = AKIAEXAMPLESHOP12345
aws_secret_access_key = shopsecretexampleThen tell the SDK which profile to use, together with the region:
export AWS_PROFILE=shop
export AWS_REGION=us-east-1In Windows PowerShell, the same two lines are $env:AWS_PROFILE = "shop" and $env:AWS_REGION = "us-east-1". An IDE run configuration needs them in its own environment settings, because an IDE started from the desktop doesn't see variables you set in a terminal later. You can also choose the profile in code, which removes any doubt about what the environment holds:
package shop;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sts.StsClient;
public class ExplicitProfile {
public static void main(String[] args) {
try (StsClient sts = StsClient.builder()
.credentialsProvider(ProfileCredentialsProvider.create("shop"))
.region(Region.US_EAST_1)
.build()) {
System.out.println(sts.getCallerIdentity().arn());
}
}
}For a quick one-off test, JVM system properties work too, and they come first in the chain:
java -Daws.accessKeyId=AKIA... -Daws.secretAccessKey=... -Daws.region=us-east-1 -cp app.jar shop.WhoAmIAvoid putting long-term keys into code or into a container image. Profiles and IAM roles keep them out of your source and your images. Our profile rules guide explains which settings belong in credentials and which in config.
Wrong keys being used? See which provider wins
The chain stops at the first provider that has credentials, which causes a quieter problem than the error: the wrong credentials. Environment variables come before profiles, so old AWS_ACCESS_KEY_ID values left in your shell beat AWS_PROFILE every time. This small program tries each provider in chain order and shows which one would be used:
package shop;
import java.util.List;
import software.amazon.awssdk.auth.credentials.*;
public class WhichCredentials {
public static void main(String[] args) {
List<AwsCredentialsProvider> chain = List.of(
SystemPropertyCredentialsProvider.create(),
EnvironmentVariableCredentialsProvider.create(),
WebIdentityTokenFileCredentialsProvider.create(),
ProfileCredentialsProvider.create(),
ContainerCredentialsProvider.builder().build(),
InstanceProfileCredentialsProvider.builder().build());
boolean found = false;
for (AwsCredentialsProvider p : chain) {
String name = p.getClass().getSimpleName();
try {
String key = p.resolveCredentials().accessKeyId();
System.out.println((found ? " also " : "USED ") + name + " (key " + key.substring(0, 4) + "...)");
found = true;
} catch (RuntimeException e) {
String reason = e.getMessage();
int end = reason.indexOf(". ");
System.out.println(" no " + name + ": " + (end > 0 ? reason.substring(0, end) : reason));
}
}
}
}With AWS_PROFILE=shop and stale access keys in the environment, it shows the trap plainly:
no SystemPropertyCredentialsProvider: Unable to load credentials from system settings
USED EnvironmentVariableCredentialsProvider (key AKIA...)
no WebIdentityTokenFileCredentialsProvider: Either the environment variable AWS_WEB_IDENTITY_TOKEN_FILE or the javaproperty aws.webIdentityTokenFile must be set.
also ProfileCredentialsProvider (key AKIA...)
no ContainerCredentialsProvider: Cannot fetch credentials from container - neither AWS_CONTAINER_CREDENTIALS_FULL_URI or AWS_CONTAINER_CREDENTIALS_RELATIVE_URI environment variables are set.
no InstanceProfileCredentialsProvider: Failed to load credentials from IMDS.The profile was there and valid, and it still lost. Unset the old variables (unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN) and the profile takes over.
SSO profiles: add the sso module, then log in
If your company uses IAM Identity Center (AWS SSO), your profile has settings such as sso_session, sso_account_id and sso_role_name instead of keys. The AWS CLI handles those on its own, but the Java SDK needs two extra modules to read them. Without them, the profile step fails with:
To use Sso related properties in the 'sso-dev' profile, the 'sso' service module must be on the class path.Add both modules next to your service module. With the SDK's BOM in your pom.xml, no versions are needed:
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sso</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>ssooidc</artifactId>
</dependency>Run again, and the message changes to the next step:
💻 Where to run these commands
Easiest: AWS CloudShell, nothing to install. Sign in to the AWS Management Console, choose your Region at the top right, then click the CloudShell icon (a small >_ terminal symbol) in the top bar, or type CloudShell in the search box and open it. When the $ prompt appears, paste a command and press Enter. CloudShell already has the AWS CLI, uses your console permissions and costs nothing extra.
On your own computer: install AWS CLI version 2 (installers for Windows, macOS and Linux are on the AWS CLI page), run aws configure once (or aws configure sso if your company signs in through single sign-on), and check it works with aws sts get-caller-identity. Then paste commands into Terminal on Mac or Linux, or PowerShell or Command Prompt on Windows.
Windows tip: a line ending in a backslash ( \ ) continues on the next line in CloudShell, Mac and Linux. In PowerShell use a backtick ( ` ) instead, in Command Prompt a caret ( ^ ), or simply join the lines into one. JSON inside single quotes works as shown in CloudShell; on Windows, save the JSON in a file and pass it as file://name.json.
Python examples: save the code in a file such as script.py, install the AWS SDK with pip install boto3, and run python script.py (python3 on Mac and Linux). It uses the same credentials as the AWS CLI; CloudShell has Python and boto3 ready.
Replace example values such as my-bucket, my-function, 111122223333 (an account ID) and us-east-1 with your own.
The SSO session associated with this profile has expired or is otherwise invalid. To refresh this SSO session run aws sso login with the corresponding profile.The Java SDK doesn't open the browser login itself; it reads the token the AWS CLI saves. So the whole SSO setup is three steps:
- Add the
ssoandssooidcmodules shown above. - Set
AWS_PROFILEto your SSO profile, or pass it toProfileCredentialsProvider.create(). - Log in once with the AWS CLI, and the Java program picks up the session:
aws sso login --profile sso-devWhen that session expires, the same message returns, and the same command fixes it. Our SSO token guide covers sessions that expire too often.
Jake: "So the program needed a library just to understand the login."
Ethan: "Yes, and then the actual login, done once with the CLI. Two steps, two error messages, each telling you the next one."
EC2 and Docker: the instance role and the hop limit
On an EC2 instance with an IAM role, the last provider in the chain fetches temporary credentials from the instance metadata service (IMDS). If it fails there with "Failed to load credentials from IMDS," check two things.
First, that the instance actually has a role, an instance profile, attached. Our instance profile guide shows how.
Second, if your program runs inside a Docker container on that instance, the request to IMDS takes one extra network hop, and the default limit for IMDSv2 responses can stop it from coming back. For containers, the setting to change is the hop limit, raised to 2:
aws ec2 modify-instance-metadata-options --instance-id i-1234567890abcdef0 \
--http-put-response-hop-limit 2 --http-endpoint enabledIf you'd rather not change the instance, pass credentials into the container another way, for example a task role if the container runs on ECS.
ECS, EKS and Lambda: give the workload its own role
- ECS: set a task role in the task definition. The ECS agent then sets
AWS_CONTAINER_CREDENTIALS_RELATIVE_URIin the container, and the container provider picks it up. A task role is not the same as the task execution role, which is what ECS itself uses, for example to pull your image and write logs. - EKS: with IAM roles for service accounts, EKS gives the pod a web identity token and sets
AWS_WEB_IDENTITY_TOKEN_FILEandAWS_ROLE_ARN; the web identity provider swaps them for credentials through AWS STS. That needs thestsmodule on your classpath; without it, the chain's reason reads "To use web identity tokens, the 'sts' service module must be on the class path." If the two variables are missing in the pod, the service account isn't linked to a role. - Lambda: the function's execution role is turned into environment variables before your code runs, and
AWS_REGIONis set too, so the default chain works with no setup. If it fails on Lambda, something in your code is overriding the chain, such as a hard-coded profile.
Still on AWS SDK for Java v1?
The AWS SDK for Java 1.x reached end of support on December 31, 2025, and recent versions print a deprecation notice when they start. Its version of this error reads differently:
com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [EnvironmentVariableCredentialsProvider: Unable to load AWS credentials from environment variables (AWS_ACCESS_KEY_ID (or AWS_ACCESS_KEY) and AWS_SECRET_KEY (or AWS_SECRET_ACCESS_KEY)), SystemPropertiesCredentialsProvider: Unable to load AWS credentials from Java system properties (aws.accessKeyId and aws.secretKey), ...Two differences matter if you're moving to v2:
| SDK v1 | SDK v2 | |
|---|---|---|
| Exception class | com.amazonaws.SdkClientException | software.amazon.awssdk.core.exception.SdkClientException |
| Checked first | Environment variables | System properties |
| Secret key system property | aws.secretKey | aws.secretAccessKey |
| Support | Ended December 31, 2025 | Current |
The system property name catches people out after a migration: -Daws.secretKey works in v1 and is ignored by v2.
Fix it in five minutes
- Read the reasons at the end of the error and find the provider you expected to work.
- If the region error appears, set
AWS_REGIONor call.region(). - On a laptop, set
AWS_PROFILEand check the profile has keys, or SSO settings plus thessomodules and a freshaws sso login. - In AWS, give the workload a role: an instance profile on EC2, a task role on ECS, a service account role on EKS.
- Run the WhichCredentials program to confirm which provider is actually used.
Troubleshooting by symptom
Works in the IDE, fails in Docker
The container doesn't have your ~/.aws folder or your shell's variables. Pass AWS_PROFILE plus a mounted ~/.aws, environment variables, or use a role.
Unable to load region with AWS_DEFAULT_REGION set
The Java SDK v2 reads AWS_REGION, not AWS_DEFAULT_REGION. Set AWS_REGION, aws.region, a profile region, or .region() in code.
'sso' service module must be on the class path
Add software.amazon.awssdk:sso and ssooidc to your dependencies, then run aws sso login --profile with that profile.
SSO session has expired or is otherwise invalid
Run aws sso login --profile NAME. The Java SDK reads the token the CLI saves.
Failed to load credentials from IMDS on EC2
Attach an instance profile with a role, and for Docker on EC2, raise the metadata hop limit to 2.
To use web identity tokens, the 'sts' service module must be on the class path
Add software.amazon.awssdk:sts to your dependencies. The web identity provider used on EKS needs it to exchange the token.
AWS_PROFILE set, but the wrong account is used
Environment variable keys beat profiles. Unset AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN.
Java SDK credentials provider chain: frequently asked questions
What does "Unable to load credentials from any of the providers in the chain" mean?
The AWS SDK for Java checked every credential source in its default chain, system properties, environment variables, web identity, profiles, ECS and EC2 metadata, and none had usable credentials.
What is the AWS SDK for Java default credentials provider chain?
In SDK v2: Java system properties, environment variables, web identity token, the shared profile files, ECS container credentials, then EC2 instance metadata. The first that works is used.
Why does the Java SDK ignore AWS_DEFAULT_REGION?
The SDK v2 region chain reads the aws.region property, the AWS_REGION variable, the profile and EC2 metadata. AWS_DEFAULT_REGION isn't one of them; set AWS_REGION instead.
How do I fix "Unable to load region from any of the providers in the chain"?
Set AWS_REGION, pass -Daws.region, add region to your profile, or call .region(Region.US_EAST_1) on the client builder.
How do I use an AWS profile in Java SDK v2?
Set AWS_PROFILE to the profile name, or build the client with ProfileCredentialsProvider.create("name"). The profile lives in ~/.aws/credentials or ~/.aws/config.
How do I use AWS SSO with the Java SDK?
Add the sso and ssooidc modules to your project, set AWS_PROFILE to the SSO profile, and run aws sso login --profile NAME. The SDK reads the cached token.
Why does my Java app use the wrong AWS credentials?
The chain stops at the first provider with credentials, and environment variables come before profiles. Old AWS_ACCESS_KEY_ID values override AWS_PROFILE.
How does the Java SDK get credentials on EC2?
From the instance profile, through the instance metadata service. In Docker on EC2, raise the metadata hop limit to 2 so the response reaches the container.
How does the Java SDK get credentials on ECS?
From the task role. The ECS agent sets AWS_CONTAINER_CREDENTIALS_RELATIVE_URI, and the container credentials provider uses it.
How does the Java SDK get credentials on EKS?
With IAM roles for service accounts, the pod gets AWS_WEB_IDENTITY_TOKEN_FILE and AWS_ROLE_ARN, and the web identity provider exchanges them for credentials through STS.
What Java system properties set AWS credentials?
In SDK v2, aws.accessKeyId, aws.secretAccessKey and aws.sessionToken, plus aws.region for the region. SDK v1 used aws.secretKey for the secret.
Is AWS SDK for Java v1 still supported?
No. It reached end of support on December 31, 2025. Its error reads "Unable to load AWS credentials from any provider in the chain."
How do I see which credentials provider the Java SDK used?
Resolve each provider in chain order yourself, as the WhichCredentials program on this page does; the first one that returns keys is the one the default chain uses.
Should I put AWS keys in my Java code?
No. Use a profile on your machine and an IAM role in AWS. Keys in code end up in repositories and images.
Does Lambda need credentials configured for the Java SDK?
No. Lambda provides the execution role's credentials and AWS_REGION as environment variables, so the default chain works without changes.
What is the difference between the ECS task role and execution role?
The task role is what your code uses to call AWS. The execution role is what ECS itself uses, for example to pull your image and send logs. A credentials error in your code points to the task role.
For readers preparing for an AWS certification
We have been covering AWS certifications alongside our fixes, so here is a short extra for readers studying for one. If you only came for the fix, you already have it; feel free to skip this part.
Exams that test this topic: Developer – Associate (DVA-C03 from December 1, 2026).
Here are the exam-style questions this topic tends to raise, with the reasoning you need to answer them:
1. Which credential providers does the default Java SDK chain check?
System properties, environment variables, web identity, the shared profile files, container credentials and instance metadata.
2. A Spring Boot app on EKS cannot load credentials. What should it use?
EKS Pod Identity or IRSA, which the SDK's default chain picks up.
3. How do you avoid the SDK v1 end-of-support issues?
Migrate to the AWS SDK for Java 2.x.
4. How do you use a named profile in Java?
Set AWS_PROFILE, or build a ProfileCredentialsProvider with the profile name.
5. Where should credentials come from on EC2?
The instance profile through instance metadata.
6. Should credentials be stored in application.properties?
No. Use roles, or Secrets Manager for non-AWS secrets.
Exam codes and dates change often. Our AWS certification changes page keeps track of what is current.
Ethan's container needed three lines in the end: AWS_PROFILE=shop, the shop's ~/.aws folder mounted read-only, and AWS_REGION where AWS_DEFAULT_REGION had been. In production, he dropped all three and gave the ECS task a role instead. He keeps the WhichCredentials program in the project's tools folder, because the next time a program uses the wrong account, it will answer the question in one run.
📌 If you keep one line from this page
The Java SDK's "providers in the chain" error ends with a reason for every place it looked; read that, set AWS_REGION rather than AWS_DEFAULT_REGION, and use roles instead of keys wherever your code runs in AWS.
Laptop → AWS_PROFILE · SSO → sso modules + aws sso login · EC2 Docker → hop limit 2 · ECS → task role · EKS → service account role.
Revision note. Written October 13, 2026, for everyone who scrolled past the useful half of a very long error. "The devil is in the details," the saying goes; in this message, the details are at the end.