private static async getDirectoriesInS3GivenPrefixes()

in auditLogMover/auditLogMoverHelper.ts [47:75]


    private static async getDirectoriesInS3GivenPrefixes(prefixes: string[], auditLogBucket: string) {
        const S3 = new AWS.S3();
        const listS3Responses: ListObjectsV2Output[] = await Promise.all(
            prefixes.map((prefix) => {
                const s3params: any = {
                    Bucket: auditLogBucket,
                    MaxKeys: 31,
                    Delimiter: '/',
                    Prefix: prefix,
                };
                return S3.listObjectsV2(s3params).promise();
            }),
        );

        const directoriesInS3: string[] = [];
        listS3Responses.forEach((response: ListObjectsV2Output) => {
            if (response.CommonPrefixes) {
                response.CommonPrefixes.forEach((commonPrefix) => {
                    // Format of Prefix is 2020-07-04/
                    // Therefore we need to remove the '/' at the end
                    if (commonPrefix.Prefix) {
                        directoriesInS3.push(commonPrefix.Prefix.slice(0, -1));
                    }
                });
            }
        });

        return directoriesInS3;
    }