0

Is there a way to get a file list from a bucket in amazon s3?

I'm using Lepozepo/S3 Package

I see this SO, which recommends using boto, but I'm wondering if there is another way to get the files.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
carloss medranoo
  • 1,399
  • 2
  • 14
  • 19

2 Answers2

1

Here is how I do it:

Use the very popular AWS SDK package: https://atmospherejs.com/peerlibrary/aws-sdk

Then the code snippet (on server) will look like:

AWS.config.update({
    accessKeyId: '<accessKey>',
    secretAccessKey: '<secretKey>'
});

s3 = new AWS.S3({
    region: 'us-west-2'
});

var params = {
    Bucket: 'bucketName'
};

s3.listObjects(params, Meteor.bindEnvironment(function (err, data) {

  //DO STUFF HERE

}));

Hope that's useful, if you have any problems, just shout!

John Furneaux
  • 166
  • 2
  • 8
  • John, is there a way to configure using IAM roles? I'd like to avoid putting access key/secret on the server or in the code at all... the aws-sdk run from nodejs uses the roles properly. However, when it's included by the peer library, it ignores the role and needs the accessKey/secret. Any feedback appreciated. – Will Kessler Oct 27 '15 at 14:47
  • Hmm, I'm afraid I don't know the answer to that one Will. I've always put the AWS keys on server. – John Furneaux Oct 30 '15 at 14:20
0

one of the way you can get the list of files from a bucket in Amazon S3 is using aws-sdk for java. below is an example of that. To get the credetials passing there are advanced methods now, which shown below is not secure.

AWSCredentials credentials = new BasicAWSCredentials(accessKeyId,secretAccessKey);
 AmazonS3 s3Client = new AmazonS3Client(credentials);
String bucket = prop.getProperty("bucket");
String directory = prop.getProperty("directory");
ListObjectsRequest lor = new ListObjectsRequest().withBucketName(bucket).withPrefix(directory);

ObjectListing objects = s3Client.listObjects(lor);

Then use the S3ObjectSummary class to iterate the objects and list the files.

Hope it helps!

scalauser
  • 1,327
  • 1
  • 12
  • 34
  • Sorry im using Javascript for this see tag [meteor], btw where did you get this API info? could you please provide the link? – carloss medranoo May 21 '15 at 14:28
  • I am sorry too.. I thought you meant another way of listing files so I understood as even another technology. Amazon provides a great documentation http://aws.amazon.com/sdk-for-java/ about aws-sdk. – scalauser May 22 '15 at 04:05