- Newest
- Most votes
- Most comments
Here are some thoughts on handling large file transfers between S3 buckets in AWS Glue:
-
To copy/move an unzipped file from a tar file:
- Use the
tarfilemodule to open and extract the tar file - Loop through the extracted file objects and upload each one to the target S3 bucket using
boto3S3 client
- Use the
import tarfile import boto3 s3 = boto3.client('s3') with tarfile.open('source.tar') as tar: for member in tar.getmembers(): file_obj = tar.extractfile(member) s3.upload_fileobj(file_obj, 'target_bucket', member.name)
-
For large files, use multipart uploads:
- Use
s3.create_multipart_uploadto initialize a multipart upload - Use
s3.upload_partin a loop to upload file chunks in parallel - After all parts uploaded, use
s3.complete_multipart_uploadto finish
- Use
This allows you to upload large files efficiently in parallel.
-
Other methods to write to S3:
- Use boto3 resource API instead of client (eg
s3.Bucket(name).upload_fileobj()) - Use AWS SDK for Python (Boto3) transfer manager which handles multipart and threading
- Write to S3 from EMR using Hadoop distcp or Spark
- Use boto3 resource API instead of client (eg
-
To make it scalable and generic:
- Parameterize bucket names, key prefixes
- Put common logic in separate module/package
- Use configuration files or environment variables for bucket names
- Automate deployments of Glue job code
Sources [1] Copying an object using multipart upload - Amazon Simple Storage Service
[2] Efficient Amazon S3 Object Concatenation Using the AWS SDK for Ruby | AWS Developer Tools Blog
[3] Using multipart uploads with directory buckets - Amazon Simple Storage Service
[4] Uploading an object using multipart upload - Amazon Simple Storage Service
[5] Uploading Files to Amazon S3 | AWS Developer Tools Blog
[6] Uploading large objects to Amazon S3 using multipart upload feature and transfer acceleration
[7] Using high-level (s3) commands in the AWS CLI - AWS Command Line Interface
answered 2 years ago
Relevant content
asked 2 years ago
asked 2 years ago

Can you please clarify little more, why are you considering glue for file transfer between s3 buckets, instead of lambda. Are there too many files to copy, files sizes are big, which can't be completed within lambda timeout(15 minutes). Are there any transformation, you'll be doing on source file before copying it to target bucket. Why aren't you considering native s3 features for file transfers(is it for specific files in a certain workflow, if so then I can understand not using native s3 features).
Thank you @secondabhi_aws.
1 . We are expecting many files and files size may be big which can't completed within 15 mins. The solution should be scalable.
2. The source and target bucket may be vary from team to team, and this solution should be generic one(this can be maintain as configurable) 3. The files in source bucket may be compressed format(zip or tar), and based on the project team requirement it may be unzip and loaded in target bucket.