我正在实现一个REST Api,需要从Amazon S3下载文件。
当我调用api时,它给了我一个例外:
com.amazonaws.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.
然后我运行了相同的方法API,它成功了。我使用的是tomcat 9.0.2,我的猜测是默认的凭证目录〜/ .aws / credential与tomcat应用程序不同。
因此,我检查了$ CATALINA_HOME,它是/opt/apache-tomcat-9.0.2,我在其中复制了凭证,但仍然无法使用。
第一次在这里提问,希望我表达清楚我的问题。感谢任何人的帮助。
答案 0 :(得分:1)
主目录~
取决于运行Tomcat服务器的用户,因此,例如,如果Tomcat以root用户身份运行,则需要将凭据放在/root/.aws/credentials
中。
根据Tomcat版本,通常可以在/etc/default/tomcat7
中找到默认用户。它将显示为:
TOMCAT7_USER=tomcat7
在这种情况下,主目录将为/home/tomcat7
,因此凭据将进入/home/tomcat7/.aws/credentials
。