in source/lambda/wf-submit-topic-model/util/extract-records.js [43:84]
async emptyBucket(destinationBucket) {
const params = {
Bucket: destinationBucket,
};
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('Calling s3 deleteObjects');
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`);
});
}
if (!objectList.IsTruncated) {
break;
}
params.StartAfter = objectList.NextContinuationToken;
}
return 'Success';
}