Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nezort11/s3-localstorage
Small and simple localStorage-compatible adaptor for S3-compatible storages
https://github.com/nezort11/s3-localstorage
localstorage localstorage-api s3 storage
Last synced: 4 days ago
JSON representation
Small and simple localStorage-compatible adaptor for S3-compatible storages
- Host: GitHub
- URL: https://github.com/nezort11/s3-localstorage
- Owner: nezort11
- Created: 2024-12-13T15:59:26.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2025-01-03T14:32:21.000Z (about 2 months ago)
- Last Synced: 2025-02-03T23:04:29.029Z (17 days ago)
- Topics: localstorage, localstorage-api, s3, storage
- Language: TypeScript
- Homepage:
- Size: 27.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# s3-localstorage
Small and simple `localStorage`-compatible adaptor for S3-compatible storages (wrapper around `@aws-sdk/client-s3`).
## Installation
```sh
npm install s3-localstorage
```## Setup
### AWS
- Open [AWS Console](https://console.aws.amazon.com/console/home) or similar
- Go to [IAM](https://console.aws.amazon.com/iam/home#/users) > Users
- Create a new user
- Enter user name and on "Set permissions" select `Attach policies directly`
- Search for and select `S3FullAccess` permission (or manually select `admin`, `editor` and `viewer` roles)
- Go to created user, click "Create access key", select `Application running outside AWS`
- Copy `Access key` and `Secret access key`
- Provide these to this package by preloading into `process.env`
## Usage
```ts
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);
};
```