Currently for AWS SDK for Java 1.x im using below code.
@Configuration
@ImportResource("classpath:aws-context.xml")
public class AmazonS3Config {
@Bean(destroyMethod = "shutdown")
public AmazonS3Client amazonS3Client(@Value("${aws.s3.roleSessionName}") String roleSessionName,
@Value("${aws.s3.roleArn}") String role) {
AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
builder.withRegion(Regions.US_EAST_1).withCredentials(new
STSAssumeRoleSessionCredentialsProvider.Builder(role, roleSessionName).build());
return (AmazonS3Client)builder.build();
}
How to do the same for AWS SDK for Java 2.x?
Thanks
The equivalent of
STSAssumeRoleSessionCredentialsProvider
in SDK V2 isStsAssumeRoleCredentialsProvider
.So the equivalent S3Client initialisation in V2 would look like below
The maven/gradle dependency group and the package names have changed to
software.amazon.awssdk
in V2. Ensure to include the dependencies forS3
andSTS
. Here is the change log and here is the migration guide.