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
This project was created based on another developed in Python. If you would like to use these methods in Python, visit this repo.
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
- 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 a S3 bucket
await createBucket({Bucket: "BucketName"});
- 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");
- Retrieve one object from AWS S3 bucket and store into local disk
await downloadObject("BucketName","existingFile.pdf", "downloadedFile.pdf");
- List all objects in a S3 bucket (with filter options)
const keysList: string[] = await listObjects("BucketName", "FolderName");
- 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 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.
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.
To run the tests for this project:
NPM:
npm run test
Yarn:
yarn test
If you encounter any problems, bugs or other issues with the package, please create an issue in the GitHub repo.