Tech Blog

Cloud Computing, Programming, Technology

Zip files from Amazon S3

By Yaswanth Bellamkonda2 min read
← Back to blog

Hello Seekers! In this blog, I will take you through the procedure of compressing files into a zip from Amazon S3 without memory or disk usage. Interesting ? Hop in then.

Amazon S3

To put it simply, Amazon S3 is a virtual drive. It is an object storage system that you can use to store, retrieve and manage unlimited amounts of data from anywhere on the internet. S3 is one of the most popular cloud storage systems and huge amounts of data is transferred over it everyday. 

Imagine we have to download a very large number of files from S3. If we can compress these files into a zip file it will reduce the download time and data usage. While Amazon offers various methods for handling data, there is no method that retrieves multiple files as a single zip file. But, there is a workaround with AWS Lambda to achieve our goal.

AWS Lambda function

AWS Lambda is a serverless compute service. It allows the users to run code for virtually any type of backend service. AWS Lambda service can function without having to provision or manage servers.

File compression with S3 and Lambda

Fundamentally, the idea is that we stream the files from AWS S3 straight into a zip file, which then streams to S3 as we add files to it. We can use the AWS Lambda function for the job. Moreover, lambda does not use memory or disk space. Hence, this is the most effective way.

Lambda code to zip files from S3

The below code receives data and saves as a zip file at destination location

{

     "bucket": "aws-bucket-name",

     "destination_key": "location-to-s3/data.zip",

     "files": [

         {

             "uri": "s3-file-key-or-url",

             "filename": "file-name-of-file-inside-zip",

             "type": "options: [file, url]"

         }

     ]

 }

After this, all you need to do is to use existing methods of AWS S3 for the coding environment you are using and download the result zip from the destination location. With this, you can zip files from Amazon S3 and allow your users to download multiple files, consuming less time and data without any real disk space and memory usage.

Keep reading

You may be interested in

Browse all articles →
Terraform As a DevOps Tool (IaC) And Benefits (Part 2)
September 21, 20222 min read

Terraform As a DevOps Tool (IaC) And Benefits (Part 2)

In this article, we will explore terminologies and basic commands that can be used to interact with Terraform. Using Terraform init, an existing or new Terraform configuration can be initialized. As a beginner, you may get syntax errors or indentation errors. To validate theYAML data, use the Terraform “validate” command. The “Terraform apply“ command changes […]

By Utsav SolankiRead More →
Terraform as a DevOps tool (IaC) and benefits (part 1)
September 21, 20222 min read

Terraform as a DevOps tool (IaC) and benefits (part 1)

Nowadays, the term “Infrastructure as Code (IaC) is very popular. This code is written in the YAML or JSON format and directly deployed in cloud services. One of the IaC tools is Terraform. It is used for creating and managing existing infrastructure, including versions of stats. Terraform supports many cloud providers, such as Amazon Web […]

By Utsav SolankiRead More →
How Angular is Different from AngularJS
September 27, 20227 min read

How Angular is Different from AngularJS

What is Angular? Angular is a popular open-source Typescript framework and free to use. Considered to be a JavaScript-based framework,TypeScript.is its primary programming language. TypeScript is Developed by Microsoft and its superset of JavaScript, which simply means that TypeScript has all the capabilities that JS has and more additional features. Angular is majorly used for […]

By Sachin DevadigaRead More →