Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

Using this code for setting the classpath

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 = key here

secretKey = secret key here

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)

1 Answer

0 votes
by (44.4k points)

The reason for this exception is because your AWS SDK is not able to load your credentials. Now, do this:

Preference → AWS → Add Secret key and Access key

This will allow your project to retrieve both the keys.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

Browse Categories

...