The AWS SDK for Java cannot find credentials, and AwsCredentials.properties does nothing
Unable to load AWS credentials from the /AwsCredentials.properties file on the classpathShort answer
AwsCredentials.properties on the classpath is an old convention: the default provider chain of the AWS SDK for Java does not read it. Put credentials where the chain looks (environment variables, the shared credentials file, or an IAM role) and move to SDK 2.x, since 1.x reached end of support on 31 December 2025.
Fix it fast
1Find out which cause you have
See which of the places the SDK checks actually hold credentials for the process that runs your code. Run this in the same shell, container or service that starts the Java app.
env | grep -E '^AWS_' ls -l ~/.aws/credentials2Match what you see, then jump to its fix
- 1
The message names AwsCredentials.properties, and no AWS_ variables or ~/.aws/credentials file exist.The credentials sit in a classpath file the default chain never readsFix - 2
~/.aws/credentials exists and has keys, but not under [default].The app reads a different profile or file than the one you filled inFix - 3
The same code works on your laptop and fails inside Docker, on ECS or on EC2.The app runs in a container or on a server with no credentials fileFix - 4
Imports start with com.amazonaws and the build uses the aws-java-sdk artifacts.The project still uses SDK 1.x, which is out of supportFix
- 1
What does the error look like?
Unable to load AWS credentials from the /AwsCredentials.properties file on the classpathsoftware.amazon.awssdk.core.exception.SdkClientException: Unable to load credentials from any of the providers in the chain
Cause 1 of 4
The credentials sit in a classpath file the default chain never reads
1Check
The default chain of SDK 1.x looks at environment variables, Java system properties, web identity tokens, the shared credentials file, ECS container credentials and EC2 instance profile credentials, in that order. A properties file on the classpath is not in the list, so creating one has no effect.
find . -name AwsCredentials.properties
ls -l ~/.aws/credentials2Fix
Put the keys into the shared credentials file (aws configure writes it), or into environment variables, and delete the classpath file so keys are not shipped inside the jar.
aws configure
# or, for one shell:
export AWS_ACCESS_KEY_ID=your-key-id
export AWS_SECRET_ACCESS_KEY=your-secret3Verify
Build the client without passing credentials and make one call; it returns instead of throwing.
s3.listBuckets();Confirmed by docs.aws.amazon.com
Cause 2 of 4
The app reads a different profile or file than the one you filled in
1Check
The SDK uses the default profile unless told otherwise. AWS_PROFILE changes it for every AWS SDK and tool, and the aws.profile system property changes it only for the Java app (the environment variable wins). In SDK 1.x the AWS_CREDENTIAL_PROFILES_FILE variable moves the file itself.
grep '^\[' ~/.aws/credentials
echo "$AWS_PROFILE $AWS_CREDENTIAL_PROFILES_FILE"2Fix
Rename the section to [default], or select the profile you want.
export AWS_PROFILE=myProfile
# Java only:
java -Daws.profile=myProfile -jar app.jar3Verify
Restart the app with the profile set and repeat the call that failed.
s3.listBuckets();Confirmed by docs.aws.amazon.com
Cause 3 of 4
The app runs in a container or on a server with no credentials file
1Check
A container does not see your home directory. On ECS the agent sets AWS_CONTAINER_CREDENTIALS_RELATIVE_URI for the task role, and on EC2 the SDK reads an instance profile from the metadata service. If neither is configured, the chain ends empty.
env | grep AWS_CONTAINER_CREDENTIALS_RELATIVE_URI2Fix
Attach an IAM role to the ECS task or the EC2 instance and let the SDK pick it up. Do not bake keys into the image.
// no credentials in code: the default chain finds the role
S3Client s3 = S3Client.builder().region(Region.US_WEST_2).build();3Verify
Call the service from the running container and confirm no credentials exception appears.
s3.listBuckets();Confirmed by docs.aws.amazon.com
Cause 4 of 4
The project still uses SDK 1.x, which is out of support
1Check
SDK for Java 1.x reached end of support on 31 December 2025. The 2.x chain is documented and maintained, and its failure message lists every provider it tried.
grep -R "com.amazonaws" --include=*.java -l src | head2Fix
Move to SDK 2.x. Build the client without a credentials provider and it uses DefaultCredentialsProvider; a named profile can be set on that provider.
DefaultCredentialsProvider provider = DefaultCredentialsProvider.builder()
.profileName("custom-profile")
.build();
S3Client s3 = S3Client.builder()
.region(Region.US_WEST_2)
.credentialsProvider(provider)
.build();3Verify
Run one call and read the exception list if it still fails.
s3.listBuckets();Confirmed by docs.aws.amazon.com
How do I stop it coming back?
- Never commit keys or ship them inside a jar; use roles in AWS and the shared credentials file on your own machine.
- Leave the credentials provider out of the client builder so the same code runs locally and in production.
- Plan the move from SDK 1.x to 2.x now that 1.x is out of support.
- Log which profile and region the app starts with, so a mismatch is visible at startup.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
- Loade DriverThe driver side of a delivery platform: live jobs, routing and earnings, past 5K Google Play downloads.
Related fixes
Back end
Android gets HTML instead of JSON from a PHP API
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
The response body is not JSON.
2 causes, each with a fixBack end
API Gateway gives up on a slow Lambda or Node.js backend
$context.integrationErrorMessage in the access log shows the integration error
API Gateway stops waiting for the backend at its integration timeout: 29 seconds by default on REST APIs, a fixed 30 seconds on HTTP APIs.
4 causes, each with a fixBack end
Application Load Balancer returns 502 for a Node.js target
HTTPCode_ELB_502_Count
An ALB returns 502 when the target gives it something it cannot use: a refused or reset connection, a connection closed mid-request, a bad response, or a header over 32 K.
4 causes, each with a fixBack end
cdk synth says --app is required
--app is required either in command-line, in cdk.json or in ~/.cdk.json
The CDK CLI needs a command that runs your app and finds it in three places: the --app option, cdk.json in the project folder, or cdk.json in your home folder.
3 causes, each with a fixBack end
The AWS SDK in Node.js cannot find any credentials
Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
The AWS SDK walks a fixed credential chain: code, environment variables, the shared files in ~/.aws, then role sources such as ECS or EC2.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fix