How to extract zip files in S3 ?

Pradip Bhattarai
2 min readApr 23, 2020

--

Artitecture of Unzipping files in S3

Scenario:

Hey all ! I had an static web application developed on my local machine and I was trying to deploy it using s3. The problem was I couldn’t find any options on S3 to upload my application folder directly. And I thought of zipping my application folder and uploading it into S3 bucket. I did so but again I was not able to unzip it inside S3 bucket. And after exploring S3 for some hours I came to know there was no direct option to unzip file in S3. Creating each folder and uploading each small files of my was little bit troublesome for me since my application was little big in size. So, i thought of automating this process and ended up with this solution :

Here are the steps that I carried out :

  1. Upload a zip file(in my case it was a zipped application folder) to a S3 bucket (source bucket).
  2. Uploding file triggers a lambda function which extracts all the files and folders inside the ZIP file and uploads into new S3 bucket(target bucket).

Since other processes are very simple so I am not going to disscuss them here. The main logic stands inside a lambda function which looks someting like this :

Here, at first the source file(zip file) is stored as bytes in memory buffer and extracted using python zipfile package. Finally, after extraction files are uploaded to new s3 bucket using s3 client. Full code can be accessed here.

To automate the process we simply add trigger to lambda function. On PUT event on source bucket we can trigger this lambda function.

By default the execution time for lambda function is set to 3 sec. In case of large zip files we may need to increase this execution time.

Hope it helps ! Thank you !

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Pradip Bhattarai
Pradip Bhattarai

Written by Pradip Bhattarai

Solutions Architect | Cloud enthusiast

Responses (6)

Write a response