I have an ECS Fargate task that downloads about 2 million CSVs that are in an S3 bucket, compresses them into a single zip archive and then saves that archive to S3. The CSVs are ~40kb. My code that runs in the Docker container is below.
I got an error though, "OSError: [Errno 28] No space left on device: '/app/data/temp/myfile.csv'"
The Fargate docs say: "For Amazon ECS on Fargate tasks using platform version 1.4.0 or later, each task receives 20 GB of ephemeral storage". (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/fargate-task-storage.html)
This makes sense that I ran into a disk error, because 40kb * 2000000 files = 80000000kb = 80Gb
I'm left with the problem of how to download these files from S3 and zip them. Is there a way to address this in parallel by generating several zip files from parallel containers? (Or a better approach entirely for generating a zip of this S3 bucket).
I can download them one by one by doing this:
aws s3 sync s3://mybucketname .
But I have been having trouble zipping them up into one file locally once they are all downloaded to my machine, my machine crashes (hence doing this on AWS).
thanks
import boto3
import os
from botocore.exceptions import ClientError
import shutil
from configs import *
s3_resource = boto3.resource('s3')
s3_client = boto3.client('s3')
source_bucket = s3_resource.Bucket(bucket)
# download CSVs
for s3_object in source_bucket.objects.all():
path, filename = os.path.split(s3_object.key)
source_bucket.download_file(s3_object.key, f"temp/{filename}") # OSError: [Errno 28] No space left on device: '/app/data/temp/myfile.csv'
# archive
shutil.make_archive(f"temp/archive", 'zip', tmp_dir)
# save to s3
s3_client.upload_file(f"temp/archive.zip", bucket, "archive.zip")