部署在aws kuberate集群中获得异常#无法加载aws凭据异常。
我尝试secretmanager API代码,但失败了。期望在没有访问密钥和密钥的情况下从秘密管理器获取秘密。请有人提供最好的解决方案。
是的,如果没有AWS AccesskeyId和SecretAccessKey,这是可能的
AWS Java SDK v1.x
在pom.xml中添加依赖项
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-secretsmanager</artifactId>
<version>1.12.347</version>
</dependency>
@Configuration
public class AwsSecretManagerConfig {
@Bean
public AWSSecretsManager awsSecretsManager(){
return AWSSecretsManagerClient
.builder()
.withCredentials(DefaultAWSCredentialsProviderChain.getInstance())
.withRegion("AWS_REGION")
.build();
}
}
AWS Java SDK v2.x
在pom.xml中添加依赖项
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>secretsmanager</artifactId>
<version>2.18.23</version>
</dependency>
@Configuration
public class AwsSecretManagerConfig {
@Bean
public SecretsManagerClient secretsManagerClient(){
return SecretsManagerClient
.builder()
.credentialsProvider(DefaultCredentialsProvider.create())
.region(Region.of("AWS_REGION"))
.build();
}
}