Unable to load AWS credentials from the /AwsCredentials.properties file on the classpath

138,650

Solution 1

You are getting this exception because your AWS SDK is unable to load your credentials. What you should do is goto Preferences then goto AWS and add your secret key and access key. So that your project can retrieve both keys.

Solution 2

I made the connection using a different approach:

BasicAWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
AmazonDynamoDBClient client = new AmazonDynamoDBClient(credentials).withRegion(Regions.US_EAST_1);
DynamoDB dynamoDB = new DynamoDB(client);

The access key and the secret key can be created in the Identity and Access Management console. I hope it helps...

Solution 3

You can use DefaultAwsCredentialsProviderChain(), which according to the documentation, looks for credentials in this order:

  1. Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY (recommended since they are recognized by all AWS SDKs and CLI except for .NET), or AWS_ACCESS_KEY and AWS_SECRET_KEY (only recognized by the Java SDK)
  2. Java System Properties - aws.accessKeyId and aws.secretAccessKey
  3. Credential profiles file at the default location (~/.aws/credentials) shared by all AWS SDKs and the AWS CLI
  4. Instance profile credentials delivered through the Amazon EC2 metadata service

Solution 4

AWSCredentialsProvider credentialsProvider = new ProfileCredentialsProvider();
new AmazonEC2Client(credentialsProvider)

.aws/credentials

[default]
aws_access_key_id =
aws_secret_access_key = 

Solution 5

Try this for the file format:

[default]
aws_access_key_id=<your access key>
aws_secret_access_key=<your secret access key>

I saved this file as ~/.aws/credentials with ProfileCredentialsProvider().

Share:
138,650
Crew HaXor
Author by

Crew HaXor

I am a student of Computer Sciences BS(CS) at FAST (NUCES) .

Updated on July 09, 2022

Comments

  • Crew HaXor
    Crew HaXor almost 2 years

    Using this code for setting the class path

    AWSCredentialsProvider credentialsProvider = new ClasspathPropertiesFileCredentialsProvider();
    ec2 = new AmazonEC2Client(credentialsProvider);
    

    Below is the format for AwsCredentials.properties file

    # Fill in your AWS Access Key ID and Secret Access Key
    # http://aws.amazon.com/security-credentials
    accessKey = keyHere
    secretKey = secretKeyHere
    

    Below is the exception I am getting

    Exception in thread "main" com.amazonaws.AmazonClientException: Unable to load AWS credentials from the /AwsCredentials.properties file on the classpath
    
        at com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider.getCredentials(ClasspathPropertiesFileCredentialsProvider.java:81)
        at com.amazonaws.services.ec2.AmazonEC2Client.invoke(AmazonEC2Client.java:8359)
    
  • Arslan Anwar
    Arslan Anwar over 9 years
    Where to put this file?
  • iForests
    iForests over 8 years
    I can't find "Preferences" and "AWS" to add key. Can you help me?
  • Abhishek Aggarwal
    Abhishek Aggarwal over 8 years
    @Arslan, put this file in <local_drive>/.aws/ folder. Like my file is located at C:\Users\Abhishek\.aws location. Full path C:\Users\Abhishek\.aws\credentials. Also, when I installed the AWS plugin in eclipse it gave me a popup to fill the Access Key and Secret Access Key and created credentials file automatically at C:\Users\Abhishek\.aws\credentials location
  • NoName
    NoName over 6 years
  • GERH
    GERH about 5 years
    This would only work if you have access to IAM. The issue is the majority of people working on AWS do not have the access due to companies locking down IAM for security reasons.
  • JavaTec
    JavaTec over 4 years
    Looking at your answer, i figured aws_access_key_id and aws_secret_access_key -> must be all lower case, that solved my issue
  • emragins
    emragins almost 4 years
    Thank you. Commenting out .withCredentials(new InstanceProfileCredentialsProvider(false)) on my Client did the trick.
  • Manabu Tokunaga
    Manabu Tokunaga over 2 years
    I did not have a new line after the aws_secret_access_key line. This works on other AWS API library but not with the Client Side Monitoring. Be aware.