2017-12-19 13 views
0

Ich versuche AWSCredentials Objekt erstellen von:ProfileCredentialsProvider: java.lang.IllegalArgumentException: Profildatei kann nicht null sein

AWSCredentials cred = new ProfileCredentialsProvider("Rafael_Nascimento").getCredentials(); 

Die Anmeldeinformationen Datei auf ~/.aws-Ordner befindet (Linux), sieht es so aus:

# 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> 

Wenn ich führen sie den Code ich auf dieser Linie erhalten:

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) 

Was könnte falsch sein? Danke!

Antwort

0

Meine Anwendung konnte die Anmeldeinformationsdatei nicht finden. Ich gelöst, dass durch die globale Umgebungsvariable zu schaffen (in /etc/environment-Datei): AWS_CREDENTIAL_PROFILES_FILE = "/ home/rafael/.aws/Credentials"

Stellen Sie sicher, Ihre Anwendung die Variable sehen:

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