DEV Community

Felipe Leao
Felipe Leao

Posted on

7 2

How to unzip .zip files from s3 bucket back to s3

The problem

  • Get an .zip file provided from s3 bucket and upload the extracted folder and its content back to s3 bucket

The solution

  • Built an npm package that gets an .zip file from s3 and create streams, with that you can do whatever you want with the extracted content.

  • You can check more and contribute to our package in: s3-zip-handler

built-in possibilities

  • Send extracted folder back to s3 bucket

import AWS from 'aws-sdk'
import s3ZipHandler, { IS3ZipFileParams } from 's3-zip-handler'

const s3Client = new AWS.S3({
...your s3 settings
})


const s3Config: IS3ZipFileParams = {
    s3Client,
    bucket: 'your-s3-bucket',
    key: 'your-s3-key/your-zip-file.zip',
    params: {
      ACL: 'public-read',
      ContentDisposition: 'inline'
    }
} 

const {
localPath, 
uploadedPath 
} = await s3ZipHandler.decompressToKeyFolderS3(s3Config)

// localPath = 'os-tmp/unzipped-xxxx/your-zip-file'
// uploadedPath  = 'your-s3-bucket/your-s3-key/your-zip-file'

Enter fullscreen mode Exit fullscreen mode
  • Manipulate locally the extracted folder
import s3ZipHandler from 's3-zip-handler'
import AWS from 'aws-sdk'

const s3Client = new AWS.S3({
    ...your s3 settings
})

const s3Config = {
    s3Client,
    bucket: 'your-s3-bucket',
    key: 'your-s3-key/your-zip-file.zip'
} 

const {
 localPath
 } = await s3ZipHandler.decompressLocal(s3Config, 'path-to-extract')

// localPath = 'path-to-extract/your-zip-file'


Enter fullscreen mode Exit fullscreen mode

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (2)

Collapse
 
brunosoares99 profile image
Bruno Soares

Nice, awesome project!

Collapse
 
felipeleao18 profile image
Felipe Leao

thanks!!!!

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay