![](/img/trans.png)
[英]java.lang.IllegalArgumentException: uri cannot be null
[英]ProfileCredentialsProvider: java.lang.IllegalArgumentException: profile file cannot be null
我正在尝试通过以下方式创建AWSCredentials对象:
AWSCredentials cred = new ProfileCredentialsProvider("Rafael_Nascimento").getCredentials();
凭证文件位于~/.aws文件夹 (Linux),如下所示:
# Move this credentials file to (~/.aws/credentials)
# after you fill in your access and secret keys in the default profile
# WARNING: To avoid accidental leakage of your credentials,
# DO NOT keep this file in your source directory.
[default]
aws_access_key_id = <default_key>
aws_secret_access_key = <default_secret_key>
[Rafael_Nascimento]
aws_secret_access_key = <secret_key_Rafael_Nascimento>
aws_access_key_id = <key_Rafael_Nascimento>
当我运行代码时,我就在那一行:
Exception in thread "main" java.lang.IllegalArgumentException: profile file cannot be null
at com.amazonaws.util.ValidationUtils.assertNotNull(ValidationUtils.java:37)
at com.amazonaws.auth.profile.ProfilesConfigFile.<init>(ProfilesConfigFile.java:142)
at com.amazonaws.auth.profile.ProfilesConfigFile.<init>(ProfilesConfigFile.java:133)
at com.amazonaws.auth.profile.ProfilesConfigFile.<init>(ProfilesConfigFile.java:100)
at com.amazonaws.auth.profile.ProfileCredentialsProvider.getCredentials(ProfileCredentialsProvider.java:135)
有什么问题? 谢谢!
我的应用程序无法找到凭据文件。 我通过创建全局环境变量(在/etc/environment文件中)解决了这个问题: AWS_CREDENTIAL_PROFILES_FILE="/home/rafael/.aws/credentials"
确保您的应用程序可以看到该变量:
System.out.println(System.getenv("AWS_CREDENTIAL_PROFILES_FILE"));
//output: /home/rafael/.aws/credentials
只是为了最终帮助那些失去太多时间使用 docker 面对这个问题的人。
只需使用-v ~/.aws:/root/.aws
标志启动 docker docker run
命令即可
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.