1.0.3 • Published 2 years ago
s3-read-write v1.0.3
Reason for existence
Could not make any sense of the ridiculously over-complicated AWS documentation.
This article sorted everything for me, so I decided to make it re-usable for my personal projects.
Usage
Install
npm i s3-read-write
const S3RW = require("s3-read-write");
const s3 = new S3RW({
accessKeyId: "YOUR_KEY_HERE",
secretAccessKey: "YOUR_SECRET_HERE",
Bucket: "YOUR_BUCKET_NAME_HERE",
});
Write
Within an async
function.
const contents = "Hello world!";
await s3.write(contents, "hello-world.txt");
Read
Within an async
function.
const contents = await s3.read("hello-world.txt");
console.log(contents); // Hello world!
Delete
Within an async
function.
await s3.delete("hello-world.txt");
Exists?
Within an async
function.
await s3.exists("hello-world.txt"); // boolean output
Testing
$ ACCESS_KEY_ID=... SECRET_ACCESS_KEY=... BUCKET=... npm test
This will attempt to
- Create a file in your bucket called "hello-world.txt" (contents: "Hello world").
- Read that file from AWS.
- Delete that file from your bucket.