skip to Main Content

I’m generating large text files that can have up to ~50 MB. Zipping them cuts the size by half, 50 MB becomes ~25 MB. Instead of uploading text files I would like to upload a zip and let S3 unzip it. Does S3 support such thing (auto unzip)?

3

Answers


  1. S3 can’t automatically unzip a file, but you can use S3 Event Notifications to invoke a Lambda that unzip the file (and then delete the zipped archive, if you want).

    Login or Signup to reply.
  2. You can configure an S3 Event Lambda on your bucket and then use this solution to automatically unzip files.

    Login or Signup to reply.
  3. You can create a Lambda function that implements RequestHandler<S3Event, String> interface.

    This gives you access to the S3 object and bucket where an update occurred. Then you can get the ZIP file and pass it to a method that can unzipped the file and get the files.

    For example, if I were to write the Lambda handler using the Java run-time API:

    public class S3Trigger implements RequestHandler<S3Event, String> {
    
        @Override
        public String handleRequest(S3Event event, Context context) {
            // Get the S3 bucket and object key from the S3 event.
            String bucketName = event.getRecords().get(0).getS3().getBucket().getName();
            String objectKey = event.getRecords().get(0).getS3().getObject().getKey();
    
            // Log the S3 bucket and object key in the log file.
            context.getLogger().log("S3 object name: s3://" + bucketName + "/" + objectKey);
    
           // Perform your logic....
     }
    }
    

    Make sure that you configure this Lambda function as an S3 Trigger in the AWS Lambda Console. Once you set the trigger up, you will see it in the AWS Management Console as shown here:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search