Giter VIP home page Giter VIP logo

aws-s3-tools's Introduction

AWS-S3-Tools

npm GitHub repo size GitHub

AWS S3 Tools is a package to make it easier to deal with S3 objects, available on NPM, where you can:

  • Create/Delete a S3 bucket
  • Check if a S3 bucket exists
  • List S3 bucket content
  • Check if a S3 object exists
  • Download S3 objects to local files
  • Delete S3 objects
  • Upload local files to S3 bucket

Table of Contents

Disclaimer

This project was created based on another developed in Python. If you would like to use these methods in Python, visit this repo.

Installation

The package is available through NPM, which means you can choose to install it using either npm or yarn

NPM:

npm install aws-s3-tools

Yarn:

yarn add aws-s3-tools

Documentation

Check

  • Check if an object exists in a S3 bucket
const exists: boolean = await objectExists("BucketName", "FileName");
  • Check if an S3 bucket exists
const exists: boolean = await bucketExists("BucketName");

Create

  • Create a S3 bucket
await createBucket({Bucket: "BucketName"});

Delete

  • Delete an object in a S3 bucket
await deleteObject("BucketName", "existingFile.pdf");
  • Delete all objects under a prefix
await deleteFromPrefix("BucketName", "folder");
  • Delete all objects in the keys list from S3 bucket
const keys = ["folder/test.pdf", "folder/file.csv"];
await deleteFromKeys("BucketName", keys);
  • Delete a S3 bucket
await deleteBucket("BucketName");

Download

  • Retrieve one object from AWS S3 bucket and store into local disk
await downloadObject("BucketName","existingFile.pdf", "downloadedFile.pdf");

List

  • List all objects in a S3 bucket (with filter options)
const keysList: string[] = await listObjects("BucketName", "FolderName");

Move

  • Move S3 object from source bucket to destination bucket
await moveObject("SourceBucketName", "SourceFileKey", "DestinationBucketName", "DestinationFileKey");
  • Move a list of S3 objects from source bucket to destination
await moveObjects("SourceBucketName", ["SourceFileKey"], "DestinationBucketName", ["DestinationFileKey"]);

Upload

  • Upload one file from local disk and store into AWS S3 bucket
await uploadObject("BucketName","s3file.pdf", "localFile.pdf");
  • Upload list of files to specific objects
await uploadObjects("BucketName",[{ key: "s3file.pdf", localFilename: "localFile.pdf" }]);
  • Upload all files for a given folder (just root files) and store them into a S3 bucket under a prefix (with filter options)
await uploadFolderToPrefix("BucketName", "s3Folder", "localFolder");

The documentation for each method supported by this module can be found here.

Authentication

To use this package, it's necessary to authenticate to AWS, using one of three options:

  • Load credentials from a json file
AWS.config.loadFromPath("./config.json");
// call methods

For more information, visit Authenticate with json file.

  • Load credentials from Shared Credentials file
AWS.config.credentials = new AWS.SharedIniFileCredentials({profile: 'work-account'});
// call methods

For more information, visit Authenticate with Shared Credentials file.

  • Load ClientId, ClientSecret and Region directly
AWS.config.update({
 accessKeyId: CLIENT_ID,
 secretAccessKey: CLIENT_SECRET,
 region: REGION
});
// call methods

For more information, visit Authenticate with Environment Variables.

Tests

To run the tests for this project:

NPM:

npm run test

Yarn:

yarn test

Problems or issues?

If you encounter any problems, bugs or other issues with the package, please create an issue in the GitHub repo.

License

MIT

aws-s3-tools's People

Contributors

pedros11 avatar

Watchers

 avatar  avatar  avatar

Forkers

andrea-mariadb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.