GCP.CloudFunctions reference
Function
Section titled “Function”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.
Function: Creating a Function
Section titled “Function: Creating a Function”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, },});Function: Event Triggers
Section titled “Function: Event Triggers”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, },});Function: Reading a Function
Section titled “Function: Reading a Function”const getFunction = yield* GCP.CloudFunctions.GetFunction(hello);const live = yield* getFunction();Function: Downloading Source
Section titled “Function: Downloading Source”const download = yield* GCP.CloudFunctions.GenerateDownloadUrl(hello);const { downloadUrl } = yield* download();Function: Effect-native Functions
Section titled “Function: Effect-native Functions”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.
GenerateDownloadUrl
Section titled “GenerateDownloadUrl”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).
GenerateDownloadUrl: Downloading Source
Section titled “GenerateDownloadUrl: Downloading Source”const download = yield* GCP.CloudFunctions.GenerateDownloadUrl(hello);const { downloadUrl } = yield* download();GenerateDownloadUrlHttp
Section titled “GenerateDownloadUrlHttp”Source:
src/GCP/CloudFunctions/GenerateDownloadUrlHttp.tsKind: Layer · Provides:GCP.CloudFunctions.GenerateDownloadUrl
HTTP implementation of GenerateDownloadUrl.
GetFunction
Section titled “GetFunction”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).
GetFunction: Reading a Function
Section titled “GetFunction: Reading a Function”const getFunction = yield* GCP.CloudFunctions.GetFunction(hello);const live = yield* getFunction();GetFunctionHttp
Section titled “GetFunctionHttp”Source:
src/GCP/CloudFunctions/GetFunctionHttp.tsKind: Layer · Provides:GCP.CloudFunctions.GetFunction
HTTP implementation of GetFunction.