我试图通过以下方式创建 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)
可能有什么不对? 谢谢!
答案 0 :(得分:1)
我的应用程序无法找到凭据文件。我通过创建全局环境变量(在 / etc / environment 文件中)解决了这个问题: 的 AWS_CREDENTIAL_PROFILES_FILE =&#34; /home/rafael/.aws/credentials" 强>
确保您的应用程序可以看到变量:
System.out.println(System.getenv("AWS_CREDENTIAL_PROFILES_FILE"));
//output: /home/rafael/.aws/credentials