in source/lambda/wf-detect-moderation-labels/util/extract-image.js [30:78]
async emptyBucket(destinationBucket, keyPrefix) {
const params = {
Bucket: destinationBucket,
Prefix: keyPrefix
};
while(true) {
const objectList = await this.s3.listObjectsV2(params).promise();
if (objectList.Contents.length == 0) {
console.debug('Bucket is empty');
break;
}
const keys = [];
objectList.Contents.forEach((element) => {
console.debug(`Key to delete is ${element.Key}`);
keys.push({ Key: element.Key });
});
console.debug(`Key are ${JSON.stringify(keys)}`);
try {
const deleteResponse = await this.s3.deleteObjects({
Bucket: destinationBucket,
Delete: {
Objects: keys,
Quiet: true
}
}).promise();
if (deleteResponse.Deleted !== undefined && deleteResponse.Deleted.length > 0) {
deleteResponse.Deleted.forEach((notDeletedKey) => {
console.warn(`${JSON.stringify(notDeletedKey)} could not be deleted`);
});
}
} catch(error) {
console.error(`Error in deleting following keys ${JSON.stringify(keys)}`, error);
throw error;
}
if (!objectList.IsTruncated) {
break;
}
params.StartAfter = data.NextContinuationToken;
}
return 'Success';
}