s3-localstorage
v1.3.0
Published
Small and simple localStorage-compatible adaptor for S3-compatible storages
Readme
s3-localstorage
Small and simple localStorage-compatible adaptor for S3-compatible storages (wrapper around @aws-sdk/client-s3).
Installation
npm install s3-localstorageSetup
AWS
Open AWS Console or similar
Go to IAM > Users
Create a new user
Enter user name and on "Set permissions" select
Attach policies directlySearch for and select
S3FullAccesspermission (or manually selectadmin,editorandviewerroles)Go to created user, click "Create access key", select
Application running outside AWSCopy
Access keyandSecret access keyProvide these to this package by preloading into
process.env
Usage
import S3LocalStorage from "s3-localstorage";
const main = async () => {
// throws `NoSuchBucket` error, if the specified bucket doesn't exist
const storage = new S3LocalStorage("user-bucket", {
region: process.env.AWS_REGION,
endpoint: process.env.AWS_S3_ENDPOINT,
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
});
await storage.setItem(
"user",
JSON.stringify({ id: 3923, name: "nezort11" })
);
const user = await storage.getItem("user");
console.log("user from s3", user);
};