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)
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.
To make requests to Amazon Web Services using the AWS SDK for Java, you must use cryptographically-signed credentials issued by AWS. You can use programmatic access keys or temporary security credentials such as AWS IAM Identity Center (successor to AWS Single Sign-On) or IAM roles to grant access to AWS resources.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With