Closed alvinhenrick closed 7 years ago
`ProfileCredentialsProvider awsCredentialsProvider = new ProfileCredentialsProvider("prod");
AWSSecurityTokenService stsClient =
AWSSecurityTokenServiceClientBuilder.standard()
.withCredentials(awsCredentialsProvider).build();
AssumeRoleRequest assumeRequest = new AssumeRoleRequest()
.withRoleArn("arn:aws:iam::962373596474:role/Nucleus-Developer")
.withDurationSeconds(3600)
.withRoleSessionName("test-upload-session");
AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRequest);
BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials(
assumeResult.getCredentials().getAccessKeyId(),
assumeResult.getCredentials().getSecretAccessKey(),
assumeResult.getCredentials().getSessionToken());
AmazonS3 s3client = AmazonS3ClientBuilder.standard().withCredentials(new
AWSStaticCredentialsProvider(temporaryCredentials)).withRegion("us-east-1").build();`
I want to supply my own AmazonS3ClientBuilder with assume Role I need that jar to be added to the classpath. It will be great if it is part of plugin. Let me know if you can add it. Thnx
@alvinhenrick Sorry I haven't try AWS STS yet. But maybe you can try to add it from your side directly:
project/plugins.sbt
:
addSbtPlugin("net.pishen" % "sbt-emr-spark" % "0.12.0")
libraryDependencies += "com.amazonaws" % "aws-java-sdk-sts" % "1.11.195"
Overwrite the default AmazonS3ClientBuilder
in your build.sbt
:
sparkS3ClientBuilder := {
val awsCredentialsProvider = new ProfileCredentialsProvider("prod")
val stsClient = AWSSecurityTokenServiceClientBuilder.standard()
.withCredentials(awsCredentialsProvider).build()
val assumeRequest = new AssumeRoleRequest()
.withRoleArn("arn:aws:iam::962373596474:role/Nucleus-Developer")
.withDurationSeconds(3600)
.withRoleSessionName("test-upload-session")
val assumeResult = stsClient.assumeRole(assumeRequest)
val temporaryCredentials = new BasicSessionCredentials(
assumeResult.getCredentials().getAccessKeyId(),
assumeResult.getCredentials().getSecretAccessKey(),
assumeResult.getCredentials().getSessionToken()
)
sparkS3ClientBuilder.value()
.withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials))
}
The default AmazonS3ClientBuilder
is created as this line.
Let me know if these can help you.
Add the dependency to plugins.sbt works perfectly.I will update the README on how to use it.
Not sure how to provide role / ARN amazon s3 client