0.4.0 • Published 2 years ago

aws-s3-tools v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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:

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

 ```typescript
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

 ```typescript
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

0.4.0

2 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago

0.0.1

3 years ago