Skip to content

GCP.CloudFunctions reference

Source: src/GCP/CloudFunctions/Function.ts

A Google Cloud Function (2nd gen) that builds source into a Cloud Run service.

Changing functionId, location, or environment replaces the function. Source, runtime, service settings, labels, and event triggers update in place.

Generated name

const hello = yield* GCP.CloudFunctions.Function("Hello", {
buildConfig: {
runtime: "nodejs20",
entryPoint: "helloHttp",
source: {
storageSource: {
bucket: "my-source",
object: "hello.zip",
},
},
},
});

Explicit id, labels, and memory

const hello = yield* GCP.CloudFunctions.Function("Hello", {
functionId: "order-http",
location: "us-central1",
description: "HTTP handler",
labels: { env: "prod" },
buildConfig: {
runtime: "nodejs20",
entryPoint: "helloHttp",
source: {
storageSource: { bucket: "my-source", object: "hello.zip" },
},
},
serviceConfig: {
availableMemory: "256Mi",
timeoutSeconds: 60,
maxInstanceCount: 10,
},
});
const consumer = yield* GCP.CloudFunctions.Function("Consume", {
buildConfig: {
runtime: "nodejs20",
entryPoint: "onMessage",
source: {
storageSource: { bucket: "my-source", object: "consumer.zip" },
},
},
eventTrigger: {
eventType: "google.cloud.pubsub.topic.v1.messagePublished",
pubsubTopic: topic.name,
},
});
const getFunction = yield* GCP.CloudFunctions.GetFunction(hello);
const live = yield* getFunction();
const download = yield* GCP.CloudFunctions.GenerateDownloadUrl(hello);
const { downloadUrl } = yield* download();

HTTP function with a Pub/Sub binding

export class Hello extends GCP.CloudFunctions.Function<Hello>()(
"Hello",
{ main: import.meta.url },
Effect.gen(function* () {
const publish = yield* GCP.PubSub.Publish(Events);
return {
fetch: Effect.gen(function* () {
yield* publish({ body: { messages: [{ data: btoa("hi") }] } }).pipe(
Effect.orDie,
);
return HttpServerResponse.text("sent");
}),
};
}).pipe(Effect.provide(GCP.PubSub.PublishHttp)),
) {}

Consume a topic

yield* GCP.PubSub.consumeTopicMessages(orders, (messages) =>
messages.pipe(Stream.runForEach(({ message }) => Effect.log(message))),
);
// …provided with Effect.provide(GCP.CloudFunctions.TopicEventSource)

With main, Alchemy bundles the program for Node.js (nodejs22 by default), uploads it, and serves it through the Functions Framework; buildConfig.source and entryPoint are managed for you. The runtime authenticates to GCP as the function’s service account.

Source: src/GCP/CloudFunctions/GenerateDownloadUrl.ts

Runtime binding for Cloud Functions functions.generateDownloadUrl.

Bind this operation to a Function in a Function/Action init phase. Provide GenerateDownloadUrlHttp. The returned URL is valid for a limited time (about 30 minutes). Grants roles/cloudfunctions.developer (the narrowest predefined role with functions.sourceCodeGet) on the project under an IAM Condition naming only the bound function (2nd gen functions accept only invoker roles on their own IAM policy).

const download = yield* GCP.CloudFunctions.GenerateDownloadUrl(hello);
const { downloadUrl } = yield* download();

Source: src/GCP/CloudFunctions/GenerateDownloadUrlHttp.ts Kind: Layer · Provides: GCP.CloudFunctions.GenerateDownloadUrl

HTTP implementation of GenerateDownloadUrl.

Source: src/GCP/CloudFunctions/GetFunction.ts

Runtime binding for Cloud Functions functions.get.

Bind this operation to a Function in a Function/Action init phase. Provide GetFunctionHttp. Grants roles/cloudfunctions.viewer on the project under an IAM Condition naming only the bound function (2nd gen functions accept only invoker roles on their own IAM policy).

const getFunction = yield* GCP.CloudFunctions.GetFunction(hello);
const live = yield* getFunction();

Source: src/GCP/CloudFunctions/GetFunctionHttp.ts Kind: Layer · Provides: GCP.CloudFunctions.GetFunction

HTTP implementation of GetFunction.