Fetch multiple object lists from the s3, match with a prefix.
2 min readFeb 11, 2020
Amazon S3 or Amazon Simple Storage Service is a service offered by Amazon Web Services that provides object storage through a web service interface.
Sometimes we want to get some same users’ or the same type of files details from s3 bucket. Then we use a prefix system that will fetch all the same types of objects. This example from JavaScript SDK.
let s3 = new AWS.S3({
accessKeyId: config.IAM_USER_KEY,
secretAccessKey: config.IAM_USER_SECRET,
Bucket: config.BUCKET_NAME
});
var params = {
Bucket: config.BUCKET_NAME,
Prefix: "5e2974142e35c5b7ce4d5c61"
};
s3.listObjects(params, function (err, data) {
if (err) {
console.log(err);
} else {
console.log(data);
}
});
Output:-
{ IsTruncated: false,
Marker: '',
Contents:
[ { Key: '5e2974142e35c5b7ce4d5c61.csv',
LastModified: 2020-02-04T10:24:22.000Z,
ETag: '"418bd15b2089e20322fb00bd5bcdf2a2"',
Size: 5401,
StorageClass: 'STANDARD',
Owner: [Object] },
{ Key: '5e2974142e35c5b7ce4d5c61.txt',
LastModified: 2020-02-04T10:27:05.000Z,
ETag: '"4a6f13906fd6cf87e56ccfa60ebf84a3"',
Size: 14621,
StorageClass: 'STANDARD',
Owner: [Object] },
{ Key:
'5e2974142e35c5b7ce4d5c6150e02a4a008a5cae3c8c3ee96270d42d.JPG',
LastModified: 2020-01-23T10:27:35.000Z,
ETag: '"c019f005cbfbf45fecd1a65a77532470"',
Size: 35064,
StorageClass: 'STANDARD',
Owner: [Object] },
{ Key:
'5e2974142e35c5b7ce4d5c61625a2405ff88bc8ea7615c349b5efbe4.JPG',
LastModified: 2020-01-23T10:27:30.000Z,
ETag: '"60384464d1196a2dec2642ce3d547f24"',
Size: 41386,
StorageClass: 'STANDARD',
Owner: [Object] },
{ Key:
'5e2974142e35c5b7ce4d5c616b3cccce08b1ee67d775abe2e2818ad8.JPG',
LastModified: 2020-01-23T10:27:28.000Z,
ETag: '"d6733732bedcf54a4686d73d916f4a25"',
Size: 40785,
StorageClass: 'STANDARD',
Owner: [Object] },
{ Key:
'5e2974142e35c5b7ce4d5c61b622f679b06761e38456f8e3fb18c3fb.JPG',
LastModified: 2020-01-23T10:27:33.000Z,
ETag: '"186ddf710fab69fc1976807db7feb7ab"',
Size: 45136,
StorageClass: 'STANDARD',
Owner: [Object] },
{ Key: '5e2974142e35c5b7ce4d5c61calllog.csv',
LastModified: 2020-01-23T10:26:23.000Z,
ETag: '"b499acb70e3d0e221d3323338aa7cb16"',
Size: 55,
StorageClass: 'STANDARD',
Owner: [Object] },
{ Key:
'5e2974142e35c5b7ce4d5c61d75cde5c75f84cb09da6bdfeb8de145e.PDF',
LastModified: 2020-02-05T12:12:27.000Z,
ETag: '"9b549bce74f4606d531e94298296d2bf"',
Size: 57917,
StorageClass: 'STANDARD',
Owner: [Object] },
{ Key: '5e2974142e35c5b7ce4d5c61signature.JPG',
LastModified: 2020-01-23T10:27:37.000Z,
ETag: '"319ca370a808d4f40225fbf4caf5d47b"',
Size: 50348,
StorageClass: 'STANDARD',
Owner: [Object] } ],
Name: 's3testingankit1',
Prefix: '5e2974142e35c5b7ce4d5c61',
MaxKeys: 1000,
CommonPrefixes: [] }
Play with perfect data.🤓
Feel free to ask any questions or queries in the comment section or you can ping me on Facebook.