我使用以下代码获取AWS凭据以连接到SQS。这是我的个人凭证,当我在qa或prod env中部署此代码时,我不应该使用我的凭据连接到SQS。此代码将在AWS中的EC2容器中运行。有什么选择可以连接到SQS,而不必像我在下面那样明确提供用户ID /密码?
@Bean
public AWSCredentialsProvider awsCredentialsProvider() {
ProfileCredentialsProvider profileCredentialsProvider = new ProfileCredentialsProvider(credentialsProvider);
try {
profileCredentialsProvider.getCredentials();
} catch (Exception e) {
throw new AmazonClientException(
"Cannot load the credentials from the credential profiles file. " +
"Please make sure that your credentials file is at the correct " +
"location (~/.aws/credentials), and is in valid format.",
e);
}
return profileCredentialsProvider;
}
AWS开发工具包将自动从实例元数据中检索凭据。无需提供任何凭据。