我正在尝试为托管在云上的Spring引导maven应用程序(Pivotal Web Services)提供凭据,以便能够上传到Amazon S3.但是,每次我尝试使用以下内容获取凭据时:
DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain();
TransferManager transferManager = new TransferManager(credentialProviderChain.getCredentials());
它说
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
[Request processing Failed; nested exception is com.amazonaws.AmazonClientException: Unable
to load AWS credentials from any provider in the chain] with root cause
2016-01-28T23:55:38.55+0000 [APP/0] OUT com.amazonaws.AmazonClientException:
Unable to load AWS credentials from any provider in the chain
关于我的凭据是否应该在beans.xml或application.properties文件中定义,我有点困惑.但我试过两个都无济于事.有人能指出我正确的方向吗?
最佳答案
查看文档! http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html
原文链接:https://www.f2er.com/spring/431464.htmlAWS凭证提供程序链,按此顺序查找凭据:
>环境变量 – AWS_ACCESS_KEY_ID和AWS_SECRET_ACCESS_KEY(推荐,因为它们被除.NET以外的所有AWS开发工具包和CLI识别),或AWS_ACCESS_KEY和AWS_SECRET_KEY(仅由Java SDK识别)
> Java系统属性 – aws.accessKeyId和aws.secretKey
>凭据配置文件文件位于所有AWS开发工具包和AWS CLI共享的默认位置(〜/ .aws / credentials)
>通过Amazon EC2元数据服务提供的实例配置文件凭据
更一般的文档在这里:http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/credentials.html