如何将命名配置文件(例如“myprofile”)指定为 AWS 凭证提供程序?
我有一个 AWS Kinesis 客户端,它当前使用存储在应用程序包中的凭证:
KinesisProducerConfiguration config = new KinesisProducerConfiguration();
config.setCredentialsProvider(new PropertiesFileCredentialsProvider("credentials.properties"));
并希望对其进行修改,使其可以使用标准 AWS 配置文件 ~/.aws/credentials
中指定的配置文件。
我可以获得这样的凭据:
String awskey = new ProfilesConfigFile()
.getAllProfiles()
.get("myprofile")
.getCredentials()
.getAWSAccessKeyId();
我需要在第一段代码中做什么才能在凭据文件中指定配置文件?
最佳答案
如果我没有正确理解你的问题,它看起来像 ProfileCredentialsProvider
可能会做你想做的事,例如:
config.setCredentialsProvider(new ProfileCredentialsProvider("credentials.properties", "myprofile"));
希望这对您有所帮助!
关于java - 在 AWS Credentials Provider 中使用标准配置文件名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36142169/