Skip to content

DigitalOcean.Functions reference

Source: packages/digitalocean/src/Functions/AccessKey.ts

A key scoped to one Functions namespace. Send keyId:secret as HTTP basic auth to the namespace’s apiHost to deploy or invoke its functions. DigitalOcean returns the secret only at create, so Alchemy keeps it in state as a Redacted value. InvokeFunction mints one per host.

const key = yield* DigitalOcean.Functions.AccessKey("ci", {
namespaceId: fns.namespaceId,
});

Source: packages/digitalocean/src/Functions/Action.ts

A function in a DigitalOcean Functions namespace (an OpenWhisk action). Code, runtime, parameters and limits update in place; a new version is deployed only when one of them changes. Set web: true to serve the function at a public URL.

const fns = yield* DigitalOcean.Functions.Namespace("fns", { region: "nyc1" });
const hello = yield* DigitalOcean.Functions.Action("hello", {
namespace: fns,
runtime: "nodejs:18",
web: true,
code: `function main(args) { return { body: "hello " + (args.name ?? "world") } }`,
});
// hello.url → https://faas-nyc1-….doserverless.co/api/v1/web/fn-…/default/…

Source: packages/digitalocean/src/Functions/Function.ts

A DigitalOcean Function running your program: an HTTPS endpoint that runs only when it’s called, billed per run. The program is bundled into one file and deployed as a web function in a Functions namespace.

An Effect handler

export default class Hello extends DigitalOcean.Functions.Function<Hello>()(
"Hello",
{ main: import.meta.url, namespace: Fns },
Effect.gen(function* () {
return {
fetch: Effect.gen(function* () {
const request = yield* HttpServerRequest;
return HttpServerResponse.text(`hello from ${request.url}`);
}),
};
}),
) {}

An async handler

src/hello.ts
export default {
async fetch(request: Request) {
return new Response("hello");
},
};
// alchemy.run.ts
const hello = yield* DigitalOcean.Functions.Function("Hello", {
main: "./src/hello.ts",
namespace: fns,
isExternal: true,
});
export default class Api extends DigitalOcean.Functions.Function<Api>()(
"Api",
{ main: import.meta.url, namespace: Fns },
Effect.gen(function* () {
const stripe = yield* DigitalOcean.Security.ReadSecret(Stripe);
return {
fetch: Effect.gen(function* () {
const key = yield* stripe.get("STRIPE_KEY");
return HttpServerResponse.text(Redacted.value(key).slice(0, 7));
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(DigitalOcean.Security.ReadSecretHttp)),
) {}

Source: packages/digitalocean/src/Functions/InvokeFunction.ts

Invoke a DigitalOcean function from a runtime and wait for its result. Binding it mints a Functions.AccessKey for the host, scoped to the function’s namespace, because DigitalOcean signs no workload identity a runtime could present instead; the key reaches the host as a secret.

export default class Api extends DigitalOcean.App<Api>()(
"Api",
{ main: import.meta.url },
Effect.gen(function* () {
const fn = yield* Resize;
const resize = yield* DigitalOcean.Functions.InvokeFunction(fn);
return {
fetch: Effect.gen(function* () {
const out = yield* resize<{ url: string }>({ width: 200 });
return HttpServerResponse.text(out.url);
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(DigitalOcean.Functions.InvokeFunctionHttp)),
) {}

Source: packages/digitalocean/src/Functions/InvokeFunctionHttp.ts Kind: Layer · Provides: DigitalOcean.Functions.InvokeFunction

InvokeFunction over the namespace’s OpenWhisk API, with a Functions.AccessKey minted for the host.

Source: packages/digitalocean/src/Functions/Namespace.ts

A DigitalOcean Functions namespace: the place functions are deployed to and served from. Each namespace has its own OpenWhisk API host. Deploy code into it with Functions.Action and schedule it with Functions.Trigger.

const fns = yield* DigitalOcean.Functions.Namespace("fns", { region: "nyc1" });

Source: packages/digitalocean/src/Functions/Trigger.ts

Runs a function on a cron schedule. The schedule, body and enabled update in place.

yield* DigitalOcean.Functions.Trigger("every-5m", {
namespaceId: fns.namespaceId,
function: cleanup.name,
cron: "*\/5 * * * *",
body: { dryRun: false },
});