Get List of Objects in S3 Bucket with Java

Often when working with files in S3, you need information about all the items in a particular S3 bucket. Below is an example class that extends the AmazonS3Client class to provide this functionality. For the most part this class has been adapted from the sample in this AWS post. Aside from some additional methods, one major difference is that the default constructor for this class uses EnvironmentVariableCredentialsProvider instead of ProfileCredentialsProvider. The main() method in the class is doing several things:

  • Creates a new BdS3Client object
  • Creates a new S3 bucket
  • Adds empty files to the new S3 bucket
  • Creates a list of object names contained in the bucket
  • Prints the object names contained in the bucket

You can view the complete implementation here: Big Datums GitHub

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">