Skip to content

AWSCredentialsProviderChain should return Exceptions from providers, not just the combined message #3160

Closed as not planned

Description

@ivankhoosty

Upcoming End-of-Support

  • I acknowledge the upcoming end-of-support for AWS SDK for Java v1 was announced, and migration to AWS SDK for Java v2 is recommended.

Describe the bug

If an error occurs when fetching secrets from the secretsmanager during Spring startup, no logs are available as described in awspring/spring-cloud-aws#165 . The only information that is available to diagnose what went wrong with DefaultCredentialsProvider is the exception stacktrace/message generated on https://github.com/aws/aws-sdk-java/blob/df2ce8afe8f1c1ecebc110b9c451de4c904250fc/aws-java-sdk-core/src/main/java/com/amazonaws/auth/AWSCredentialsProviderChain.java#L142C38-L142C100

In my situation, ContainerCredentialsProvider provided message "Failed to load credentials from metadata service.", but the original (proxy/network/etc related) cause Exception was not visible in the logs, as

log.debug("Unable to load credentials from " + message);
doesn't actually produce any logs at this early stage.

The workaround was to replace DefaultCredentialsProvider with ContainerCredentialsProvider to see the cause Exception and fix the issue.

@maciejwalkowiak

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

I would want to see the exceptions that caused each provider to fail in the stacktrace of the

throw new SdkClientException("Unable to load AWS credentials from any provider in the chain: "

Current Behavior

only messages from the exceptions that caused each provider to fail are part of the exception generated on

throw new SdkClientException("Unable to load AWS credentials from any provider in the chain: "

Reproduction Steps

this is only reproducible if your app is fetching secrets via spring.config.import: aws-secretsmanager . Failures during this boostrap stage do not have any logs printed.

Possible Solution

Chain causes of failures of all providers and set as the cause for the exception thrown on line 142 ?

Additional Information/Context

No response

AWS Java SDK version used

2.28.28

JDK version used

21.0.1

Operating System and version

unix

Activity

  1. added
    bugThis issue is a bug.
    needs-triageThis issue or PR still needs to be triaged.
    on Nov 7, 2024
  2. debora-ito commented on Nov 7, 2024

    @debora-ito
    Member

    Hi @ivankhoosty Java SDK 1.x is in Maintenance Mode, it'll only get security updates and critical bug fixes. We don't have plans to change the logging.

    The workaround was to replace DefaultCredentialsProvider with ContainerCredentialsProvider to see the cause Exception and fix the issue.

    This is exactly the instruction we give when troubleshooting credential issues: replace the default chain for the credential provider you expect to be used, and check the logs.

  3. added
    feature-requestA feature should be added or improved.
    closing-soonThis issue will close in 2 days unless further comments are made.
    and removed
    bugThis issue is a bug.
    needs-triageThis issue or PR still needs to be triaged.
    on Nov 7, 2024
  4. ivankhoosty commented on Nov 7, 2024

    @ivankhoosty
    Author

    @debora-ito I have just noticed I pasted the links to sdk 1.x by mistake, I had both open to compare the code, and 2.x classes code is the same.

  5. debora-ito commented on Nov 7, 2024

    @debora-ito
    Member

    In 2.x if you set the log level to DEBUG you'll see the stacktraces of the individual credential provider calls in the chain:

    <Logger name="software.amazon.awssdk" level="DEBUG" />
    
  6. removed
    closing-soonThis issue will close in 2 days unless further comments are made.
    on Nov 7, 2024
  7. added
    closing-soonThis issue will close in 2 days unless further comments are made.
    on Nov 7, 2024
  8. ivankhoosty commented on Nov 11, 2024

    @ivankhoosty
    Author

    That’s not what happens because of the stage in spring boot loader. I will prepare a sample spring boot app to show you the issue

  9. removed
    closing-soonThis issue will close in 2 days unless further comments are made.
    on Nov 11, 2024
  10. maciejwalkowiak commented on Nov 11, 2024

    @maciejwalkowiak

    @ivankhoosty perhaps this issue should be moved to https://github.com/awspring/spring-cloud-aws project?

  11. ivankhoosty commented on Nov 12, 2024

    @ivankhoosty
    Author

    @maciejwalkowiak I dont know what you can do when Spring is not logging DeferredLog during boostrap failure.

    I think AwsCredentialsProviderChain appending error messages from various credentialsProviders to use it as the SdkClientException message is not consistent, they should be chaining the actual exceptions into the cause of SdkClientException as well. @debora-ito makes a comment above "This is exactly the instruction we give when troubleshooting credential issues: replace the default chain for the credential provider you expect to be used, and check the logs." - this would not be necessary at all if exceptions from credentialsProviders were preserved and stored in SdkClientException

  12. debora-ito commented on Nov 12, 2024

    @debora-ito
    Member

    "... replace the default chain for the credential provider you expect to be used, and check the logs" is the instruction when using Java SDK 1.x.

    In Java SDK 2.x you can see the full stacktraces when you use DEBUG level logging. Maybe this is a configuration that spring-cloud-aws needs to expose? We wouldn't like to change to print those at regular level as they are pretty verbose and will be printed with every client that uses the default chain.

  13. ivankhoosty commented on Nov 13, 2024

    @ivankhoosty
    Author

    @debora-ito the code in AWSCredentialsProviderChain and AwsCredentialsProviderChain resolveCredentials() methods is pretty much the same as to how it logs credentialProvider exceptions. I am not talking about changing logging level, that would make no difference to this issue.

    I am interested in exceptions not being lost, so if ALL providers fail, we can still see them in the stacktrace:

    public AwsCredentials resolveCredentials() {
    if (reuseLastProviderEnabled && lastUsedProvider != null) {
    return CredentialUtils.toCredentials(CompletableFutureUtils.joinLikeSync(lastUsedProvider.resolveIdentity()));
    }

    List<String> exceptionMessages = new ArrayList<>();
    **List<Throwable> exceptions = new ArrayList<>();**
    
    for (IdentityProvider<? extends AwsCredentialsIdentity> provider : credentialsProviders) {
        try {
            AwsCredentialsIdentity credentials = CompletableFutureUtils.joinLikeSync(provider.resolveIdentity());
    
            log.debug(() -> "Loading credentials from " + provider);
    
            lastUsedProvider = provider;
            return CredentialUtils.toCredentials(credentials);
        } catch (RuntimeException e) {
            // Ignore any exceptions and move onto the next provider
            String message = provider + ": " + e.getMessage();
            log.debug(() -> "Unable to load credentials from " + message, e);
    
            exceptionMessages.add(message);
            **exceptions.add(e);**
        }
    }
    
    SdkClientException sdkClientException = SdkClientException.builder()
        .message("Unable to load credentials from any of the providers in the chain " + this + " : " + exceptionMessages)
        .build();
    

    //SdkClientException.builder doesn't support addSuppressed, so have to add directly to the exception
    for (Throwable exception : exceptions) {
    sdkClientException.addSuppressed(exception);
    }

    throw sdkClientException;
    

    }

    can be optimised to generate exceptionMessages from the exceptions list.

  14. added
    needs-reviewThis issue or PR needs review from the team.
    p2This is a standard priority issue
    on Nov 27, 2024
  15. debora-ito commented on Dec 9, 2025

    @debora-ito
    Member

    This issue got overlooked in the Java SDK v1 repo, so closing as stale.

    @ivankhoosty if this is still relevant when Java SDK v2 is used, please create an issue in the v2 repo, ideally with a sample case we can use to repro - https://github.com/aws/aws-sdk-java-v2

  16. github-actions commented on Dec 9, 2025

    @github-actions

    This issue is now closed.

    Comments on closed issues are hard for our team to see.
    If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestA feature should be added or improved.needs-reviewThis issue or PR needs review from the team.p2This is a standard priority issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions