Suppose you have a lot of files in a folder in an S3 bucket and want to move all files into a B folder. How would you do that?
💡 Model Answer
I would use the boto3 library to interact with S3. First, list all objects in the source prefix using list_objects_v2. Then iterate over each key, construct the new key by replacing the source prefix with the destination prefix (e.g., 'A/' → 'B/'). For each object, call copy_object with the source bucket/key and the new key, then delete the original object with delete_object. This approach works for small to medium workloads. For very large numbers of objects, I would use S3 Batch Operations or the AWS CLI --copy-objects command, which can perform the move in parallel and is more efficient. Complexity is O(n) where n is the number of objects, and the operation is I/O bound.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.
Get Assisting AI — Starts at ₹500