using the below code, Im able to list the files in s3 bucket. I would like to know how to copy/move the files from s3 one bucket (s3-dev) to another s3 bucket(s3-prod) based on file names. eg if a file with name "abc-21-04-2021.csv" is placed in s3 Bucket (s3-dev), how to find the filename starting with "abc" and copy/move to another s3 bucket.
consider the files in s3-dev Bucket as 1)abc-21-04-2021.csv, 2)abc-19-04-2021.csv, 3)def-18-04-2021.csv, i need to move files starting with "abc" into another s3 bucket (s3-prod).
please suggest and share your inputs.
my_bucket = s3.Bucket('s3-dev')
for my_bucket_object in my_bucket.objects.all():
print(my_bucket_object.key)```
I guess your code written in python, you just need to handle the bucket object as string.
my_bucket = s3.Bucket('s3-dev')
for my_bucket_object in my_bucket.objects.all():
file_name = my_bucket_object.key.split('/')[-1] # avoid the folder contains the pattern
if file_name.startswith('abc'):
print(my_bucket_object.key)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.