ProfileCredentialsProvider:java.lang.IllegalArgumentException:配置文件不能为null

ProfileCredentialsProvider:java.lang.IllegalArgumentException:配置文件不能为null,java,aws-sdk,Java,Aws Sdk,我试图通过以下方式创建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 k

我试图通过以下方式创建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>
#将此凭据文件移动到(~/.aws/credentials)
#在默认配置文件中填写访问和密钥后
#警告:为避免您的凭据意外泄漏,
#不要将此文件保存在源目录中。
[默认值]
aws\u访问\u密钥\u id=
aws\u密码\u访问\u密钥=
[Rafael_Nascimento]
aws\u密码\u访问\u密钥=
aws\u访问\u密钥\u id=
当我运行代码时,我会看到这一行:

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)
线程“main”java.lang.IllegalArgumentException中的异常:配置文件不能为null 在com.amazonaws.util.ValidationUtils.assertNotNull(ValidationUtils.java:37) 位于com.amazonaws.auth.profile.ProfilesConfigFile.(ProfilesConfigFile.java:142) 在com.amazonaws.auth.profile.ProfilesConfigFile上。(ProfilesConfigFile.java:133) 位于com.amazonaws.auth.profile.ProfilesConfigFile.(ProfilesConfigFile.java:100) 在com.amazonaws.auth.profile.ProfileCredentialsProvider.getCredentials上(ProfileCredentialsProvider.java:135) 有什么不对劲吗?
谢谢

我的应用程序无法找到凭据文件。我通过创建全局环境变量(在/etc/environment文件中)解决了这个问题: AWS\u凭证\u档案文件=“/home/rafael/.AWS/credentials”

确保应用程序可以看到变量:

 System.out.println(System.getenv("AWS_CREDENTIAL_PROFILES_FILE"));
    //output: /home/rafael/.aws/credentials

你刚刚救了我一天。