@@ -24,16 +24,19 @@ def lambda_handler(event, context):
2424
2525 # Get as many files from S3 as we can move this time (minimum of queueSpace and dripRate)
2626 s3Client = boto3 .client ('s3' )
27- response = s3Client .list_objects_v2 (Bucket = sourceBucket , MaxKeys = (min (dripRate , queueSpace )))
27+ maxKeys = min (dripRate , queueSpace ) + 10 # list a few additional keys to allow for some folder objects that won't be moved
28+ response = s3Client .list_objects_v2 (Bucket = sourceBucket , MaxKeys = maxKeys )
2829 if "Contents" in response :
2930 # We now have a list of objects that we can use
3031 sourcePrefix = "/" + sourceBucket + "/"
3132 keyPrefix = targetAudioKey
3233 if keyPrefix != "" :
3334 keyPrefix += "/"
34- for audioFile in response ["Contents" ]:
35+ files = [f for f in response ["Contents" ] if not f ["Key" ].endswith ("/" )][:dripRate ] # ignore folder objects
36+ for audioFile in files :
3537 try :
3638 # Copy and delete file
39+ print (f'Copying: Bucket={ targetBucket } , CopySource={ (sourcePrefix + audioFile ["Key" ])} , Key={ (keyPrefix + audioFile ["Key" ])} ' )
3740 copyResponse = s3Client .copy_object (Bucket = targetBucket ,
3841 CopySource = (sourcePrefix + audioFile ["Key" ]),
3942 Key = (keyPrefix + audioFile ["Key" ]))
@@ -58,5 +61,5 @@ def lambda_handler(event, context):
5861 "dripRate" : 50 ,
5962 "filesProcessed" : 0 ,
6063 "queueSpace" : 250
61- }
64+ }
6265 lambda_handler (event , "" )
0 commit comments