Skip to content

Instantly share code, notes, and snippets.

@warrenronsiek
Created May 11, 2020 11:33
Show Gist options
  • Select an option

  • Save warrenronsiek/2539df3ab2a186d6b7883d2dea4952d9 to your computer and use it in GitHub Desktop.

Select an option

Save warrenronsiek/2539df3ab2a186d6b7883d2dea4952d9 to your computer and use it in GitHub Desktop.
Create amazon client with specified role
import com.amazonaws.services.s3.{AmazonS3, AmazonS3ClientBuilder}
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider
import com.amazonaws.regions.Regions
val credsWithRole: STSAssumeRoleSessionCredentialsProvider = new STSAssumeRoleSessionCredentialsProvider
.Builder("role-arn","test-session")
.withStsClient(AWSSecurityTokenServiceClientBuilder.standard().withRegion(Regions.US_EAST_1).build()).build()
val client: AmazonS3 = AmazonS3ClientBuilder.standard().withCredentials(credsWithRole)
.withRegion(Regions.US_EAST_1).build()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment