gpt4 book ai didi

java - AWS SDK 2 承担角色

转载 作者:行者123 更新时间:2023-12-05 08:38:24 26 4
gpt4 key购买 nike

@Bean
public DynamoDbClient amazonDynamoDB() {
final AssumeRoleRequest assumeRoleRequest = AssumeRoleRequest.builder().roleSessionName(UUID.randomUUID().toString()).roleArn("roleArn").build();
final StsAssumeRoleCredentialsProvider stsAssumeRoleCredentialsProvider = StsAssumeRoleCredentialsProvider.builder().refreshRequest(assumeRoleRequest).build();
return DynamoDbClient.builder().credentialsProvider(stsAssumeRoleCredentialsProvider).region(Region.EU_WEST_1)
.build();
}

获取错误

Caused by: org.springframework.beans.BeanInstantiationException:Failed to instantiate[software.amazon.awssdk.services.dynamodb.DynamoDbClient]: Factorymethod 'amazonDynamoDB' threw exception; nested exception isjava.lang.NullPointerException: STS client must not be null. atspring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)atspring.beans@5.2.7.RELEASE/org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650)... 58 common frames omitted Caused by:java.lang.NullPointerException: STS client must not be null.

最佳答案

在承担角色请求中需要设置 sts 客户端 & 它有效

@Bean
@Primary
public DynamoDbClient amazonDynamoDB() {
final AssumeRoleRequest assumeRoleRequest = AssumeRoleRequest.builder().roleSessionName(UUID.randomUUID().toString()).roleArn("roleArn").build();
final StsClient stsClient = StsClient.builder().region(Region.EU_WEST_1).build();
final StsAssumeRoleCredentialsProvider stsAssumeRoleCredentialsProvider = StsAssumeRoleCredentialsProvider.builder().stsClient(stsClient).refreshRequest(assumeRoleRequest).build();
return DynamoDbClient.builder().credentialsProvider(stsAssumeRoleCredentialsProvider).region(Region.EU_WEST_1)
.build();
}

关于java - AWS SDK 2 承担角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62921548/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com