Reputation: 111
Here is the code that I am using to listSummaries
of objects (it's 99% the same from http://docs.aws.amazon.com/AmazonS3/latest/dev/ListingObjectKeysUsingJava.html).
AmazonS3 s3client = new AmazonS3Client(new ProfileCredentialsProvider());
System.out.println("bucketname = " + bucketName + "key =" + key);
ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(key);
List<S3ObjectSummary> summaries = new ArrayList<S3ObjectSummary>();
ObjectListing objectListing;
do {
line 147 >>> objectListing = s3client.listObjects(listObjectsRequest);
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
summaries.add(objectSummary);
}
listObjectsRequest.setMarker(objectListing.getNextMarker());
} while (objectListing.isTruncated());
Here is where it says that you can use anonymous credentials to access publicly accessible buckets (http://docs.aws.amazon.com/AmazonS3/latest/dev/AuthUsingAcctOrUserCredJava.html) I am sure that the bucket I am accessing is open-sourced. I am getting the following error message and I have no idea why that is happening:
Exception in thread "main" java.lang.IllegalArgumentException: AWS credential profiles file not found in the given path: /home/xxx/.aws/credentials
at com.amazonaws.auth.profile.internal.ProfilesConfigFileLoader.loadProfiles(ProfilesConfigFileLoader.java:45)
at com.amazonaws.auth.profile.ProfilesConfigFile.loadProfiles(ProfilesConfigFile.java:194)
at com.amazonaws.auth.profile.ProfilesConfigFile.<init>(ProfilesConfigFile.java:119)
at com.amazonaws.auth.profile.ProfilesConfigFile.<init>(ProfilesConfigFile.java:93)
at com.amazonaws.auth.profile.ProfileCredentialsProvider.getCredentials(ProfileCredentialsProvider.java:149)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3589)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3548)
at com.amazonaws.services.s3.AmazonS3Client.listObjects(AmazonS3Client.java:647)
at xxx.xxx.xxx.LocalInterface.ListBucket(LocalInterface.java:147)
Upvotes: 5
Views: 1547
Reputation: 111
I figured out my own answer. I was not using anonymous credentials. Here's how to use them:
AWSCredentials creds = new AnonymousAWSCredentials();
AmazonS3 s3client = new AmazonS3Client(creds);
Hope this helps someone.
Upvotes: 6