Skip to content

Glue Job - S3 to S3

0

Hi Team,

I am working on Glue to job to copy/move file from one bucket to another bucket. Could you please help me with your thoughts

  1. Using Python how to copy/move the unzipped file to target bucket if the source file is tar type ?
  2. Using Python how to use stream and multiple part upload approach to handle large file
  3. As per my understanding we can write file to target bucket using either assume writer or secret &access key. Would like know if any other methods are available other than these 2 methods ?

Note : The source and target bucket may be in same or different AWS account, same or different region

Thank you in advance !

  • 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.

asked 2 years ago711 views

1 Answer
0

Here are some thoughts on handling large file transfers between S3 buckets in AWS Glue:

  1. To copy/move an unzipped file from a tar file:

    • Use the tarfile module to open and extract the tar file
    • Loop through the extracted file objects and upload each one to the target S3 bucket using boto3 S3 client
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)
  1. For large files, use multipart uploads:

    • Use s3.create_multipart_upload to initialize a multipart upload
    • Use s3.upload_part in a loop to upload file chunks in parallel
    • After all parts uploaded, use s3.complete_multipart_upload to finish

This allows you to upload large files efficiently in parallel.

  1. 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
  2. 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

AWS

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.