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.
  • An optional Options object to set public read accesss.

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";
import { S3Client } from "@aws-sdk/client-s3";

const imagesBucket = new Bucket("workloads-images");
const documentsBucket = new Bucket("workloads-images", { publicRead: true });

const s3Client = new S3Client({
  // Configure forcePathStyle and endpoint
  // when the dev or test container is running
  ...(process.env.ML_AWS_ENDPOINT_URL
    ? {
        forcePathStyle: true,
        endpoint: process.env.ML_AWS_ENDPOINT_URL,
       }
    : {}),
  // Other configuration options
}),

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

const documentsBucket = new Bucket("workloads-images", { publicRead: true });

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
publicReadpublicbooleanWhether the bucket has public read access permissions. Default false