java 无法检索亚马逊凭证

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35074556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 23:42:14  来源:igfitidea点击:

Can't retrieve Amazon Credentials

javaspringamazon-web-servicespivotal-web-services

提问by Tometoyou

I am trying to provide credentials for my Spring boot maven application hosted on the cloud (Pivotal Web Services) to be able to upload to Amazon S3. However, every time I try to get the credentials using:

我正在尝试为托管在云(Pivotal Web Services)上的 Spring boot maven 应用程序提供凭证,以便能够上传到 Amazon S3。但是,每次我尝试使用以下方法获取凭据时:

DefaultAWSCredentialsProviderChain credentialProviderChain = new DefaultAWSCredentialsProviderChain();
TransferManager transferManager = new TransferManager(credentialProviderChain.getCredentials());

It says

它说

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

I'm a bit confused as to whether my credentials should be defined in a beans.xml or application.properties file. But I have tried both to no avail. Could someone point me in the right direction?

对于我的凭据是否应该在 beans.xml 或 application.properties 文件中定义,我有点困惑。但是我两个都试过都无济于事。有人能指出我正确的方向吗?

回答by Stephen Rosenthal

Check out the docs! http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html

查看文档!http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html

AWS credentials provider chain that looks for credentials in this order:

按以下顺序查找凭证的 AWS 凭证提供程序链:

  • Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY (RECOMMENDED since they are recognized by all the AWS SDKs and CLI except for .NET), or AWS_ACCESS_KEY and AWS_SECRET_KEY (only recognized by Java SDK)
  • Java System Properties - aws.accessKeyId and aws.secretKey
  • Credential profiles file at the default location (~/.aws/credentials) shared by all AWS SDKs and the AWS CLI
  • Instance profile credentials delivered through the Amazon EC2 metadata service
  • 环境变量 - AWS_ACCESS_KEY_ID 和 AWS_SECRET_ACCESS_KEY(推荐,因为它们被除 .NET 之外的所有 AWS 开发工具包和 CLI 识别),或 AWS_ACCESS_KEY 和 AWS_SECRET_KEY(仅被 Java 开发工具包识别)
  • Java 系统属性 - aws.accessKeyId 和 aws.secretKey
  • 默认位置 (~/.aws/credentials) 中的凭证配置文件由所有 AWS 开发工具包和 AWS CLI 共享
  • 通过 Amazon EC2 元数据服务交付的实例配置文件凭证

More general docs here: http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/credentials.html

更一般的文档在这里:http: //docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/credentials.html

回答by Raj Hassani

this approach worked:

这种方法有效:

$ export AWS_ACCESS_KEY_ID=...
$ export AWS_SECRET_ACCESS_KEY=...