The AWS documentation seems still to refer to AWS Java SDK1 with regard to STS / assume role authentication.
If I have:
..is there a way to create with those:
One should use StsAssumeRoleCredentialsProvider
that does the refreshing of temporary tokens for you.
def apply(roleArn: String, externalId: String, expires: FiniteDuration, sessionName: String): StsAssumeRoleCredentialsProvider = {
val durationSecs: Int = expires.toSeconds.toInt
val stsClient: StsClient = StsClient.builder.build()
val req: AssumeRoleRequest = AssumeRoleRequest.builder
.roleArn(roleArn)
.externalId(externalId)
.durationSeconds(durationSecs)
.roleSessionName(sessionName)
.build()
StsAssumeRoleCredentialsProvider.builder
.stsClient(stsClient)
.refreshRequest(req)
.build()
}
Note that when calling .resolveCredentials()
the AWS SDK 2 returns an AwsCredentials
that does not provide the session token. The returned value can just be casted to AwsSessionCredentials
which provides all the three.
val prov: AwsCredentialsProvider = ???
val creds: AwsSessionCredentials = prov.resolveCredentials().asInstanceOf[AwsSessionCredentials]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With