How to copy complete folder structure to another folder in AWS s3

Viewed 22

I have below folder structure in S3 bucket Source:

2022-09-09/EOD/9898/STAGED/1/abc.txt

2022-09-09/EOD/9898/STAGED/1/test.csv

2022-09-09/EOD/9898/STAGED/2/abc1.txt

2022-09-09/EOD/9898/STAGED/2/test1.csv

Destination:

2022-09-09/EOD/9898/PROCESSED/1/abc.txt

2022-09-09/EOD/9898/PROCESSED/1/test.csv

2022-09-09/EOD/9898/PROCESSED/2/abc1.txt

2022-09-09/EOD/9898/PROCESSED/2/test1.csv

The contents under STAGED directory should be copied to PROCESSED directory with exact child directories .

Tried below code .But no luck:

String dest=("2022-09-09/EOD/9898/).concat("PROCESSED").concat("/");
String source=("2022-09-09/EOD/9898/).concat("STAGED").concat("/");

ListObjectRequest lst=new ListObjectRequest().withBucketName("myBucket").withPrefix(source).withDelimiter("/");
ObjectListing list=amazonS3.listObjects(lst)
list.getObjectSummaries()./stream().forEach(s3Summary->{

CopyObjectRequest cor=new CopyObjectRequest ("myBucket",s3Summary.getKey(),"s3Summary",dest);
amazonS3.copyObject(cor);
});

Did not work..Can some one please help

0 Answers
Related