I'm new to nodeJS and Currently implementing a copy end point to copy files in S3 bucket to another using nodeJS. So the Lambda function that I need to write, needs to copy .m3u8 files and Its corresponding .ts files to another bucket while providing different name to the .m3u8 file. If the naming format of the source .m3u8 file is ${mediaId1}.m3u8 then the copied .m3u8 file should be ${mediaId2}.m3u8. The source .m3u8 and its corresponding .ts files are in the same bucket and the .ts files and fellow .m3u8 files don't need to change its name while coping, so only the main .m3u8 needs to get copied while changing its name.
I tried coping .m3u8 file as follows.
const SourceKey = `${result.Item.system}/${result.Item.prefix}/${result.Item.mediaId}/AppleHLS1/${result.Item.mediaId}.m3u8`;
const TargetKey = `${result.Item.system}/${data.prefix}/${targertmediaId}/AppleHLS1/${targertmediaId}.m3u8`;
var paramsS3 = {
Bucket: process.env.S3_BUCKET_NAME_OUTPUT,
Key: TargetKey,
Metadata: data.metadata,
SourceKey: SourceKey,
};
s3.copyObject(paramsS3, function (error, data) {
if (error) console.log(error, error.stack);
else console.log(data)
});
So Is there any possible way that I can list the remaining .ts and .m3u8 files in the bucket and copy them one by one, without coping each at once.
Here is the bucket that all the .ts and .m3u8 files are located. Only the last .m3u8 file need to change its name while other .m3u8 and .ts remaining same while coping.

