This repository provides an implementation for interacting with an S3-compatible storage service using AWS Signature Version 4 authentication. The S3Operations class enables various S3 operations such as creating, deleting, and managing buckets and objects.
Ensure you have the following installed:
- Bun (JavaScript runtime)
- AWS Credentials (Access Key ID, Secret Access Key, and Region)
- An S3-compatible storage endpoint
Clone the repository and install dependencies:
bun installTo authenticate S3 requests, initialize the AWSSignatureV4 class with your AWS credentials:
const signature = new AWSSignatureV4(
client.accessKeyId!,
client.secretAccessKey!,
client.region,
's3',
);Create an instance of S3Operations with your S3-compatible storage endpoint:
const s3a = new S3Operations('https://s3.nevaobjects.id', signature);-
Create a bucket:
await s3a.createBucket({ Bucket: 'my-bucket' });
-
Delete a bucket:
await s3a.deleteBucket({ Bucket: 'my-bucket' });
-
List all buckets:
const buckets = await s3a.listBuckets(); console.log(buckets);
-
Upload an object:
const file = Bun.file('./sample.txt'); await s3a.putObject({ Bucket: 'my-bucket', Key: 'sample.txt', Body: file });
-
Retrieve an object:
const object = await s3a.getObject({ Bucket: 'my-bucket', Key: 'sample.txt' }); console.log(object);
-
Delete an object:
await s3a.deleteObject({ Bucket: 'my-bucket', Key: 'sample.txt' });
Generate a temporary URL to access an object:
const url = await s3a.presign({ Bucket: 'my-bucket', Key: 'sample.txt' });
console.log(url);Run the test suite to validate the implementation:
bun testThis project is licensed under the MIT License.