lsProvider与roleSessionName和roleA

lsProvider与roleSessionName和roleA

本文介绍了如何将STSAssumeRoleSessionCredentialsProvider与roleSessionName和roleArn结合使用,用于适用于Java 2.x的AWS开发工具包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前使用以下代码针对适用于Java 1.x的AWS开发工具包.

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();
   }

如何对适用于Java 2.x的AWS开发工具包执行相同的操作?

How to do the same for AWS SDK for Java 2.x?

谢谢

推荐答案

要了解如何使用V2 StsClient 返回一组临时安全凭证,请看以下示例:

TO learn how to return a set of temporary security credentials using the V2 StsClient, look at this example:

"> https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javav2/example_code/sts/src/main/java/com/example/sts/AssumeRole.java

您可以在此处找到相应的POM文件:

You can find the corresponding POM file here:

https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/javav2/example_code/sts

所有Java V2服务代码示例均位于此处:

All Java V2 Service code examples are located here:

https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/javav2

Java V2 DEV指南在此处-https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/home.html

Java V2 DEV Guide is here - https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/home.html

这篇关于如何将STSAssumeRoleSessionCredentialsProvider与roleSessionName和roleArn结合使用,用于适用于Java 2.x的AWS开发工具包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 03:22