1
votes

My AWS profile in ~/.aws/credentials contains session credentials created by STS.

[default]
aws_session_token=XXX
aws_access_key_id=XXX
aws_secret_access_key=XXX

I am trying to access these credentials using the AWS SDK Java v2

Using the DefaultCredentialsProvider or ProfileCredentialsProvider finds them, but the returned object is of type AwsCredentials rather than AwsSessionCredentials which doesn't include the session token, only the access key ID and secret access key.

Is there any way to retrieve the full session credentials?

2

2 Answers

0
votes

AwsCredentials is an interface.

public interface AwsCredentials {
    String accessKeyId();
    String secretAccessKey();
}

and its implemented by AwsBasicCredentials and AwsSessionCredentials.

Based on whether session token is set or not, proper class will be returned to you when one calls resolveCredentials() API.

0
votes

instead of using AwsCredentials/AwsSessionCredentials why dont you like to use Aws4PresignerParams it will gives you all three params (aws_session_token,aws_access_key_id and aws_secret_access_key).