Unable to load AWS credentials from the /AwsCredentials.properties file on the classpath
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:
- Environment Variables -
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
(recommended since they are recognized by all AWS SDKs and CLI except for .NET), orAWS_ACCESS_KEY
andAWS_SECRET_KEY
(only recognized by the Java SDK) - Java System Properties -
aws.accessKeyId
andaws.secretAccessKey
- Credential profiles file at the default location (
~/.aws/credentials
) shared by all AWS SDKs and the AWS CLI - 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().
Crew HaXor
I am a student of Computer Sciences BS(CS) at FAST (NUCES) .
Updated on July 09, 2022Comments
-
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 over 9 yearsWhere to put this file?
-
iForests over 8 yearsI can't find "Preferences" and "AWS" to add key. Can you help me?
-
Abhishek Aggarwal over 8 years@Arslan, put this file in
<local_drive>/.aws/
folder. Like my file is located atC:\Users\Abhishek\.aws
location. Full pathC:\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 atC:\Users\Abhishek\.aws\credentials
location -
NoName over 6 years
-
GERH about 5 yearsThis 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 over 4 yearsLooking at your answer, i figured aws_access_key_id and aws_secret_access_key -> must be all lower case, that solved my issue
-
emragins almost 4 yearsThank you. Commenting out
.withCredentials(new InstanceProfileCredentialsProvider(false))
on my Client did the trick. -
Manabu Tokunaga over 2 yearsI 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.