Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access AWS session token from profile with DefaultCredentialsProvider

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?

like image 661
user5633550 Avatar asked Dec 15 '25 04:12

user5633550


1 Answers

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.

like image 199
Ravi Pandit Avatar answered Dec 16 '25 23:12

Ravi Pandit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!