Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

S3Operations with AWSSignatureV4

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.

Prerequisites

Ensure you have the following installed:

  • Bun (JavaScript runtime)
  • AWS Credentials (Access Key ID, Secret Access Key, and Region)
  • An S3-compatible storage endpoint

Installation

Clone the repository and install dependencies:

bun install

Configuration

Setting Up AWS Signature Version 4

To authenticate S3 requests, initialize the AWSSignatureV4 class with your AWS credentials:

const signature = new AWSSignatureV4(
    client.accessKeyId!,
    client.secretAccessKey!,
    client.region,
    's3',
);

Connecting to an S3-Compatible Storage

Create an instance of S3Operations with your S3-compatible storage endpoint:

const s3a = new S3Operations('https://s3.nevaobjects.id', signature);

Usage

Bucket Operations

  • 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);

Object Operations

  • 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' });

Generating a Presigned URL

Generate a temporary URL to access an object:

const url = await s3a.presign({ Bucket: 'my-bucket', Key: 'sample.txt' });
console.log(url);

Running Tests

Run the test suite to validate the implementation:

bun test

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages