Reputation: 475
I'm trying to create AWSCredentials object by:
AWSCredentials cred = new ProfileCredentialsProvider("Rafael_Nascimento").getCredentials();
The credentials file is located at ~/.aws folder (Linux), it looks like:
# 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>
When I run the code I get on that line:
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)
What could be wrong? Thanks!
Upvotes: 3
Views: 7418
Reputation: 3630
Just for eventually help someone that lost too time facing this problem using docker.
Just launch docker run
command with -v ~/.aws:/root/.aws
flag and it works
Upvotes: 0
Reputation: 475
My application wasn't able to find the credentials file. I solved that by creating the global environment variable (in /etc/environment file): AWS_CREDENTIAL_PROFILES_FILE="/home/rafael/.aws/credentials"
Make sure your application can see the variable:
System.out.println(System.getenv("AWS_CREDENTIAL_PROFILES_FILE"));
//output: /home/rafael/.aws/credentials
Upvotes: 2