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(): stringReturns
string
Constructors
new Bucket()
ts
new Bucket(id, options?): BucketParameters
| Parameter | Type | Description |
|---|---|---|
|
| Bucket ID. |
| Bucket options |
Returns
Overrides
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
id | readonly | string | Unique ID |
publicRead | public | boolean | Whether the bucket has public read access permissions. Default false |