Troubleshooting - AWS SDK does not find credentials

Published on - Updated on

From time to time, when using the AWS SDK, you will run into the issue that the SDK fails to locate the proper credentials even though you are sure that credentials are available either on the local filesystem or through the AWS metadata endpoint if you're running on an EC2 instance. Below are some things you can try to make things work.

Step 1: Did you configure the right AWS SDK profile?

Pass the AWS_PROFILE environment variable to your application to ensure the correct profile is selected.

Step 2: Are you using Single Sign-On (SSO)?

If you use SSO to authenticate (for example, in a development environment), ensure the AWS SDK SSO library is on your classpath.

Java / Maven

<dependency>
   <groupId>software.amazon.awssdk</groupId>
   <artifactId>sso</artifactId>
</dependency>

Ensure you are logged in properly by running:

aws sso login --profile <your-profile>

Step 3: Are you trying to assume a role or use a web identity token?

If you're using AWS' Secure Token Service (STS), you must have the AWS SDK's STS library on your classpath.

Java / Maven

<dependency>
   <groupId>software.amazon.awssdk</groupId>
   <artifactId>sts</artifactId>
</dependency>