wait-for-s3-object
Simple tool to let you:
-
Wait for a specific S3 object to exist.
-
Run a callback once the object exists.
-
Check if an S3 object exists.
waitForObjectToExist(filekey, bucketname, waitingCallback, finishedCallback, delayMs=2000)
checkIfObjectExists(fileKey,bucketName,callback)
Works by polling the s3api
command via the aws cli.
Installation
First install and configure the AWS cli
Then install with npm
npm i wait-for-s3-object
Usage - wait for S3 object to exist
var tool = require('wait-for-s3-object');
var fileKey = 'folderName/myFile.txt';
var bucket = 'my-awesome-s3-bucket';
tool.waitForObjectToExist(fileKey, bucket, function(err,res){
console.log('waiting...');
}, function(err,res){
console.log('object exists!');
})
Usage - check if S3 object exists
tool.checkIfObjectExists(fileKey,bucket, function(err,res){
if(res){
console.log("object exists", res);
//res is an object like this:
//{
// AcceptRanges: 'bytes',
// LastModified: '2021-03-18T22:02:51+00:00',
// ContentLength: 1224,
// ETag: '"..."',
// ContentType: 'text/plain',
// Metadata: {}
//}
}else{
//object does not exist, or cannot be accessed
console.log("object does not exist", err); //err is a usually a 404 error
}
})