Skip to content

Railway.Bucket reference

Source: src/Railway/Bucket.ts

A Railway.Bucket is S3-compatible object storage in a Project. Each environment gets its own isolated instance and credentials. Bind PutObject / GetObject (and the other S3 object ops) in Service init — Alchemy injects the endpoint and credentials.

Railway has no labels. Ownership is stamped into the display name via createPhysicalName. name updates in place. Changing project, environment, or region replaces the Bucket.

Pass a Project. Alchemy generates a unique name and deploys to the project’s primary environment in sjc.

const site = yield* Railway.Project("Site");
const data = yield* Railway.Bucket("Data", { project: site });

Pass name when you need a stable display name. The S3 API name is this plus a short hash (s3BucketName).

const data = yield* Railway.Bucket("Data", {
project: site,
name: "uploads",
});

Omit region to use sjc. Changing it replaces the Bucket.

const data = yield* Railway.Bucket("Data", {
project: site,
region: "iad",
});

Defaults to the Project’s primary environment. Pass a Railway.Environment (or { environmentId }) to target another one.

const staging = yield* Railway.Environment("Staging", { project: site });
const data = yield* Railway.Bucket("StagingData", {
project: site,
environment: staging,
});

Railway buckets speak the S3 API. Bind PutObject / GetObject in Service init.

import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
export default class Api extends Railway.Service<Api>()(
"Api",
{ project: Site, main: import.meta.url },
Effect.gen(function* () {
const putObject = yield* Railway.PutObject(Data);
const getObject = yield* Railway.GetObject(Data);
return {
fetch: Effect.gen(function* () {
yield* putObject({
Key: "hello.txt",
Body: "hello",
ContentType: "text/plain",
});
const obj = yield* getObject({ Key: "hello.txt" });
return HttpServerResponse.json({ ok: obj.ETag !== undefined });
}),
};
}).pipe(Effect.provide([Railway.PutObjectHttp, Railway.GetObjectHttp])),
) {}

Declare the Project once. Pass it into every child. Resource-valued props accept the resource or an Effect producing it.

src/data.ts
import * as Railway from "alchemy/Railway";
export const Site = Railway.Project("Site");
export const Data = Railway.Bucket("Data", { project: Site });

Source: src/Railway/DeleteObject.ts

Runtime binding for Railway DeleteObject over the S3 API.

Bind this operation to a Bucket in Service init. Provide DeleteObjectHttp.

const deleteObject = yield* Railway.DeleteObject(Data);
yield* deleteObject({ Key: "hello.txt" });

Source: src/Railway/DeleteObjectHttp.ts Kind: Layer · Provides: Railway.DeleteObject

HTTP implementation of DeleteObject. Calls distilled S3 deleteObject against the Railway endpoint with the bucket’s credentials.

Source: src/Railway/GetObject.ts

Runtime binding for Railway GetObject over the S3 API.

Bind this operation to a Bucket in Service init. Provide GetObjectHttp.

const getObject = yield* Railway.GetObject(Data);
const text = yield* getObject({ Key: "hello.txt" }).pipe(
Effect.flatMap((result) =>
Stream.mkString(Stream.decodeText(result.Body!)),
),
);

Source: src/Railway/GetObjectHttp.ts Kind: Layer · Provides: Railway.GetObject

HTTP implementation of GetObject. Calls distilled S3 getObject against the Railway endpoint with the bucket’s credentials.

Source: src/Railway/HeadObject.ts

Runtime binding for Railway HeadObject over the S3 API.

Bind this operation to a Bucket in Service init. Provide HeadObjectHttp.

const headObject = yield* Railway.HeadObject(Data);
const head = yield* headObject({ Key: "hello.txt" });

Source: src/Railway/HeadObjectHttp.ts Kind: Layer · Provides: Railway.HeadObject

HTTP implementation of HeadObject. Calls distilled S3 headObject against the Railway endpoint with the bucket’s credentials.

Source: src/Railway/ListObjectsV2.ts

Runtime binding for Railway ListObjectsV2 over the S3 API.

Bind this operation to a Bucket in Service init. Provide ListObjectsV2Http.

const listObjects = yield* Railway.ListObjectsV2(Data);
const result = yield* listObjects({ Prefix: "jobs/", MaxKeys: 100 });

Source: src/Railway/ListObjectsV2Http.ts Kind: Layer · Provides: Railway.ListObjectsV2

HTTP implementation of ListObjectsV2. Calls distilled S3 listObjectsV2 against the Railway endpoint with the bucket’s credentials.

Source: src/Railway/PutObject.ts

Runtime binding for Railway PutObject over the S3 API.

Bind this operation to a Bucket in Service init. The bucket name, endpoint, and credentials are injected automatically. Provide PutObjectHttp.

const putObject = yield* Railway.PutObject(Data);
yield* putObject({
Key: "hello.txt",
Body: "Hello, world!",
ContentType: "text/plain",
});

Source: src/Railway/PutObjectHttp.ts Kind: Layer · Provides: Railway.PutObject

HTTP implementation of PutObject. Calls distilled S3 putObject against the Railway endpoint with the bucket’s credentials.