AWS SDK:无法导入 AWSSecurityTokenServiceClientBuilder 以获取临时凭证
AWS SDK: cannot import AWSSecurityTokenServiceClientBuilder to get temp credentials
在 AWS SDK 上有几个如何获取凭据的示例,例如:
- https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/prog-services-sts.html
- https://docs.aws.amazon.com/AmazonS3/latest/dev/AuthUsingTempSessionTokenJava.html
但是当我 运行 这些片段时我无法导入 AWSSecurityTokenServiceClientBuilder
:
// note that the AWS SDK is pretty brittle across versions.
import $ivy.`com.amazonaws:aws-java-sdk:1.7.4`
import $ivy.`org.apache.hadoop:hadoop-aws:2.7.3`
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.services.securitytoken.model.AssumeRoleRequest
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder
var clientRegion = "*** Client region ***";
var roleARN = "*** ARN for role to be assumed ***";
var roleSessionName = "*** Role session name ***";
var stsClient = AWSSecurityTokenServiceClientBuilder.standard()
.withCredentials(new ProfileCredentialsProvider())
.withRegion(clientRegion)
.build()
var roleRequest = new AssumeRoleRequest()
.withRoleArn(roleARN)
.withRoleSessionName(roleSessionName)
var roleResponse = stsClient.assumeRole(roleRequest)
var sessionCredentials = roleResponse.getCredentials()
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder
^cmd16.sc:13: not found: value AWSSecurityTokenServiceClientBuilder
var stsClient = AWSSecurityTokenServiceClientBuilder.standard()
^Compilation Failed
Compilation Failed
- scala 版本 2.11.12
- spark 版本 2.3.4,这意味着我对 hadoop-aws 2.7.3 很紧张,这取决于 aws-java-sdk 1.7.4 :/
AFAICS,在版本 1.11.0 之前,此 class 不是 AWS Java SDK 的一部分。
您必须自己实例化 AWSSecurityTokenServiceClient
class,而不是使用构建器。
称之为 constructor:
val stsClient = new AWSSecurityTokenServiceClient(new ProfileCredentialsProvider())
stsClient.setRegion(clientRegion)
在 AWS SDK 上有几个如何获取凭据的示例,例如:
- https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/prog-services-sts.html
- https://docs.aws.amazon.com/AmazonS3/latest/dev/AuthUsingTempSessionTokenJava.html
但是当我 运行 这些片段时我无法导入 AWSSecurityTokenServiceClientBuilder
:
// note that the AWS SDK is pretty brittle across versions.
import $ivy.`com.amazonaws:aws-java-sdk:1.7.4`
import $ivy.`org.apache.hadoop:hadoop-aws:2.7.3`
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.services.securitytoken.model.AssumeRoleRequest
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder
var clientRegion = "*** Client region ***";
var roleARN = "*** ARN for role to be assumed ***";
var roleSessionName = "*** Role session name ***";
var stsClient = AWSSecurityTokenServiceClientBuilder.standard()
.withCredentials(new ProfileCredentialsProvider())
.withRegion(clientRegion)
.build()
var roleRequest = new AssumeRoleRequest()
.withRoleArn(roleARN)
.withRoleSessionName(roleSessionName)
var roleResponse = stsClient.assumeRole(roleRequest)
var sessionCredentials = roleResponse.getCredentials()
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder
^cmd16.sc:13: not found: value AWSSecurityTokenServiceClientBuilder
var stsClient = AWSSecurityTokenServiceClientBuilder.standard()
^Compilation Failed
Compilation Failed
- scala 版本 2.11.12
- spark 版本 2.3.4,这意味着我对 hadoop-aws 2.7.3 很紧张,这取决于 aws-java-sdk 1.7.4 :/
AFAICS,在版本 1.11.0 之前,此 class 不是 AWS Java SDK 的一部分。
您必须自己实例化 AWSSecurityTokenServiceClient
class,而不是使用构建器。
称之为 constructor:
val stsClient = new AWSSecurityTokenServiceClient(new ProfileCredentialsProvider())
stsClient.setRegion(clientRegion)