Skip to content

workloads / main / Bucket

Class: Bucket ​

Workload for an AWS S3 compatible storage.

The Bucket workload is initialized with:

  • A valid bucket name.

NOTES

Launching the development or test containers with npx monolayer start dev will write the environment variable ML_AWS_ENDPOINT_URL will be written to the corresponding dotenv file (.env or .env.test)

When initializing the S3 client, you need to configure forcePathStyle and endpoint if the dev or test container is running (check for the ML_AWS_ENDPOINT_URL environment variable). See the example.

Example ​

ts
import { Bucket } from "@monolayer/sdk";

const documents = new Bucket("documents");

export default documents;

// Client configuration

import { S3Client } from "@aws-sdk/client-s3";
import { bucketLocalConfiguration } from "@monolayer/sdk";
export const s3Client = new S3Client({
  ...bucketLocalConfiguration(),
});

// Get Object

const response = await s3Client.send(
  new GetObjectCommand({
    Bucket: documents.name,
    Key: "README.md",
  }),
);

Extends ​

Accessors ​

name ​

Get Signature ​

ts
get name(): string
Returns ​

string

Constructors ​

new Bucket() ​

ts
new Bucket(id, options?): Bucket

Parameters ​

ParameterTypeDescription

id

string

Bucket ID.

options?

BucketOptions

Bucket options

Returns ​

Bucket

Overrides ​

StatefulWorkload.constructor

Properties ​

PropertyModifierTypeDescription
idreadonlystringUnique ID
publicAccesspublicPublicAccessDefines public access permissions for specific paths within the bucket. This allows anonymous users to perform actions on objects matching the specified path patterns.