DigitalOcean.Spaces reference
Bucket
Section titled “Bucket”Source:
packages/digitalocean/src/Spaces/Bucket.ts
A DigitalOcean Spaces bucket: S3-compatible object storage in one
region. acl, versioning, cors, lifecycleRules and
forceDestroy update in place; name and region replace the bucket.
Spaces speaks the S3 API, which signs with Spaces access keys rather than the DigitalOcean token. Alchemy uses the Spaces keys in your profile when it has them, and otherwise creates a full-access key for the deploy and deletes it afterwards.
Spaces buckets have no tags. Alchemy owns a bucket whose name it
generated or that it recorded; a bucket that already has the chosen name
on the team is Unowned and needs --adopt.
Bucket: Creating a Bucket
Section titled “Bucket: Creating a Bucket”A private bucket
const assets = yield* DigitalOcean.Spaces.Bucket("assets", { region: "nyc3" });A public bucket for static files, with CORS
const site = yield* DigitalOcean.Spaces.Bucket("site", { region: "nyc3", acl: "public-read", cors: [{ allowedOrigins: ["*"], allowedMethods: ["GET", "HEAD"] }],});Bucket: Keeping Versions and Expiring Objects
Section titled “Bucket: Keeping Versions and Expiring Objects”const uploads = yield* DigitalOcean.Spaces.Bucket("uploads", { region: "sfo3", versioning: true, lifecycleRules: [ { id: "expire-tmp", prefix: "tmp/", expirationDays: 30 }, { id: "abort-multipart", abortIncompleteMultipartUploadDays: 7 }, ],});Bucket: Serving Through the CDN
Section titled “Bucket: Serving Through the CDN”const site = yield* DigitalOcean.Spaces.Bucket("site", { region: "nyc3", acl: "public-read" });const cdn = yield* DigitalOcean.Spaces.CdnEndpoint("site-cdn", { origin: site.domainName });// Serve from https://${cdn.endpoint}CdnEndpoint
Section titled “CdnEndpoint”Source:
packages/digitalocean/src/Spaces/CdnEndpoint.ts
The Spaces CDN in front of a bucket: edge caching for the bucket’s
public objects. ttl, customDomain and certificateId update in
place; a new origin replaces the endpoint. One endpoint per bucket.
CdnEndpoint: Serving a Bucket Through the CDN
Section titled “CdnEndpoint: Serving a Bucket Through the CDN”const assets = yield* DigitalOcean.Spaces.Bucket("assets", { region: "nyc3", acl: "public-read",});const cdn = yield* DigitalOcean.Spaces.CdnEndpoint("assets-cdn", { origin: assets.domainName, ttl: 86400,});// https://${cdn.endpoint}/logo.png serves assets/logo.png from the edge.DeleteObject
Section titled “DeleteObject”Source:
packages/digitalocean/src/Spaces/DeleteObject.ts
Deletes an object. Binding it grants the host a Spaces key with readwrite access to the
one bucket.
DeleteObject: Examples
Section titled “DeleteObject: Examples”export default class Api extends DigitalOcean.App<Api>()( "Api", { main: import.meta.url }, Effect.gen(function* () { const deleteObject = yield* DigitalOcean.Spaces.DeleteObject(Uploads); return { fetch: Effect.gen(function* () { yield* deleteObject({ Key: "hello.txt" }); return HttpServerResponse.text("ok"); }).pipe(Effect.orDie), }; }).pipe(Effect.provide(DigitalOcean.Spaces.DeleteObjectHttp)),) {}DeleteObjectHttp
Section titled “DeleteObjectHttp”Source:
packages/digitalocean/src/Spaces/DeleteObjectHttp.tsKind: Layer · Provides:DigitalOcean.Spaces.DeleteObject
DeleteObject over the Spaces S3 API, signed with a key scoped to the bound bucket.
GetObject
Section titled “GetObject”Source:
packages/digitalocean/src/Spaces/GetObject.ts
Reads an object. Binding it grants the host a Spaces key with read access to the
one bucket.
GetObject: Examples
Section titled “GetObject: Examples”export default class Api extends DigitalOcean.App<Api>()( "Api", { main: import.meta.url }, Effect.gen(function* () { const getObject = yield* DigitalOcean.Spaces.GetObject(Uploads); return { fetch: Effect.gen(function* () { const object = yield* getObject({ Key: "hello.txt" }); const text = yield* Stream.mkString(Stream.decodeText(object.Body!)); return HttpServerResponse.text("ok"); }).pipe(Effect.orDie), }; }).pipe(Effect.provide(DigitalOcean.Spaces.GetObjectHttp)),) {}GetObjectHttp
Section titled “GetObjectHttp”Source:
packages/digitalocean/src/Spaces/GetObjectHttp.tsKind: Layer · Provides:DigitalOcean.Spaces.GetObject
GetObject over the Spaces S3 API, signed with a key scoped to the bound bucket.
HeadObject
Section titled “HeadObject”Source:
packages/digitalocean/src/Spaces/HeadObject.ts
Reads an object’s metadata without its body. Binding it grants the host a Spaces key with read access to the
one bucket.
HeadObject: Examples
Section titled “HeadObject: Examples”export default class Api extends DigitalOcean.App<Api>()( "Api", { main: import.meta.url }, Effect.gen(function* () { const headObject = yield* DigitalOcean.Spaces.HeadObject(Uploads); return { fetch: Effect.gen(function* () { const head = yield* headObject({ Key: "hello.txt" }); return HttpServerResponse.text("ok"); }).pipe(Effect.orDie), }; }).pipe(Effect.provide(DigitalOcean.Spaces.HeadObjectHttp)),) {}HeadObjectHttp
Section titled “HeadObjectHttp”Source:
packages/digitalocean/src/Spaces/HeadObjectHttp.tsKind: Layer · Provides:DigitalOcean.Spaces.HeadObject
HeadObject over the Spaces S3 API, signed with a key scoped to the bound bucket.
Source:
packages/digitalocean/src/Spaces/Key.ts
A Spaces access key: an S3 access key id and secret scoped to buckets.
Give one to a runtime or a tool that reads and writes Spaces through the
S3 API. name and grants update in place.
DigitalOcean returns the secret only when the key is created, so Alchemy
keeps it in state as a Redacted value. A key whose state is lost cannot
be recovered; Alchemy finds a generated-name key again and replaces it.
Key: Scoped Keys
Section titled “Key: Scoped Keys”const uploads = yield* DigitalOcean.Spaces.Bucket("uploads", { region: "nyc3" });const key = yield* DigitalOcean.Spaces.Key("uploads-key", { grants: [{ bucket: uploads.bucketName, permission: "readwrite" }],});// key.accessKeyId and key.secretAccessKey sign S3 requests to uploads.endpoint.ListObjectsV2
Section titled “ListObjectsV2”Source:
packages/digitalocean/src/Spaces/ListObjectsV2.ts
Lists the objects under a prefix. Binding it grants the host a Spaces key with read access to the
one bucket.
ListObjectsV2: Examples
Section titled “ListObjectsV2: Examples”export default class Api extends DigitalOcean.App<Api>()( "Api", { main: import.meta.url }, Effect.gen(function* () { const listObjects = yield* DigitalOcean.Spaces.ListObjectsV2(Uploads); return { fetch: Effect.gen(function* () { const page = yield* listObjects({ Prefix: "uploads/" }); return HttpServerResponse.text("ok"); }).pipe(Effect.orDie), }; }).pipe(Effect.provide(DigitalOcean.Spaces.ListObjectsV2Http)),) {}ListObjectsV2Http
Section titled “ListObjectsV2Http”Source:
packages/digitalocean/src/Spaces/ListObjectsV2Http.tsKind: Layer · Provides:DigitalOcean.Spaces.ListObjectsV2
ListObjectsV2 over the Spaces S3 API, signed with a key scoped to the bound bucket.
PutObject
Section titled “PutObject”Source:
packages/digitalocean/src/Spaces/PutObject.ts
Writes an object. Binding it grants the host a Spaces key with readwrite access to the
one bucket.
PutObject: Examples
Section titled “PutObject: Examples”export default class Api extends DigitalOcean.App<Api>()( "Api", { main: import.meta.url }, Effect.gen(function* () { const putObject = yield* DigitalOcean.Spaces.PutObject(Uploads); return { fetch: Effect.gen(function* () { yield* putObject({ Key: "hello.txt", Body: "hello", ContentType: "text/plain" }); return HttpServerResponse.text("ok"); }).pipe(Effect.orDie), }; }).pipe(Effect.provide(DigitalOcean.Spaces.PutObjectHttp)),) {}PutObjectHttp
Section titled “PutObjectHttp”Source:
packages/digitalocean/src/Spaces/PutObjectHttp.tsKind: Layer · Provides:DigitalOcean.Spaces.PutObject
PutObject over the Spaces S3 API, signed with a key scoped to the bound bucket.