Badmiral
Badmiral

Reputation: 1589

aws java sdk not returning all folders

Running

$ aws s3 ls s3://mybucket/myfolder/subfolder/monitor/

and it is returning all the files I expect. I have permissions and credentials set up correctly. Then I have written some java code:

public class S3Sample {
    public static void main(String[] args) throws IOException {
    AWSCredentials credentials = null;
    try {
        credentials = new ProfileCredentialsProvider().getCredentials();
    } catch (Exception e) {
        throw new AmazonClientException(
                "Cannot load the credentials from the credential profiles file. " +
                "Please make sure that your credentials file is at the correct " +
                "location (~/.aws/credentials), and is in valid format.",
                e);
    }

    AmazonS3 s3 = new AmazonS3Client(credentials);
    try {

        ObjectListing objectListing = s3.listObjects(new ListObjectsRequest()
                    .withBucketName("mybucket"));
                        for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
                System.out.println(objectSummary.getKey());
                        }

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon S3, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }

}

The code is printing out things in mybucket/myfolder/subfolder, but nothing in monitor (and is missing other subdirectories). I am not seeing any errors. How can I diagnose why I am not seeing more of the files. I clearly have permissions to the folders and credentials are working. Any suggestions are helpful. Thanks!

Upvotes: 1

Views: 339

Answers (1)

dimoniy
dimoniy

Reputation: 5995

Just a guess, but maybe all of the results just don't fit into one response. See if ObjectListing#getNextMarker is not null.

Upvotes: 1

Related Questions