Cameleer

Google Cloud Functions component

The google-functions component calls Google Cloud Functions (1st gen) and manages them: list, get, create, update, delete and source upload URLs.

Scheme: google-functions: · Crate: cameleer-cloud · Cargo feature: cloud · Consumer: no · Producer: yes · Apache Camel: Google Functions

When to use it

  • Call a function from a route with the message body as input and its result as the new body.
  • Offload one heavy step (image resize, scoring, an ML model) to a serverless function.
  • Give an AI agent a tool: the agent's request goes through a route that calls the function.
  • Deploy or update a function from a pipeline (createFunction, updateFunction).

URI format

text
google-functions://functionName[?options]

Example

Expose a function behind an HTTP endpoint; the request body is the call data and the response is the function's result:

yaml example: google-functions-call-from-http
- route:
    id: http-to-function
    from:
      uri: "platform-http:/greet?httpMethodRestrict=POST"
      steps:
        - to: "google-functions://{{env:FUNCTION_NAME:greet}}?project={{env:GCP_PROJECT:my-project}}&location={{env:FUNCTION_LOCATION:europe-west1}}"
        - log: "execution ${header.CamelGoogleCloudFunctionsExecutionId}: ${body}"

Rust DSL

rust
ctx.add_routes(|b| {
    b.from("platform-http:/greet")
        .to("google-functions://greet?project=my-project&location=europe-west1");
})?;

Options

optiondefaultdescription
projectthe key's projectGoogle Cloud project.
locationus-central1Region of the function.
operationcallFunctioncallFunction, listFunctions, getFunction, deleteFunction, generateUploadUrl, generateDownloadUrl, createFunction, updateFunction. Header CamelGoogleCloudFunctionsOperation.
entryPointcreateFunction / updateFunction: entry point.
runtimecreateFunction / updateFunction: runtime, for example nodejs20.

client and pojoRequest are accepted for Camel compatibility and ignored. Credentials are shared by all Google components: see credentials.

Operations

  • callFunction: the body (text, or a map / list sent as JSON) is the call data; the body becomes the result. A function error raises an ApiException.
  • listFunctions: body = list of function names. getFunction: the function resource. deleteFunction: deletes it.
  • generateUploadUrl: body = a signed upload URL; with a byte body the zip archive is uploaded to it right away. generateDownloadUrl: body = the URL of the function's source.
  • createFunction / updateFunction: from the entry point, runtime and source headers (HTTPS trigger by default), or a map body that is the CloudFunction resource. The long-running operation is polled until done; body = the function.

Message headers

headerdirectiondescription
CamelGoogleCloudFunctionsOperationinOperation.
CamelGoogleCloudFunctionsExecutionIdoutCameleer: execution id of callFunction.
CamelGoogleCloudFunctionsEntryPointinEntry point for create / update.
CamelGoogleCloudFunctionsRuntimeinRuntime for create / update.
CamelGoogleCloudFunctionsSourceArchiveUrlings:// source archive for create / update.
CamelGoogleCloudFunctionsSourceUploadUrlinUpload URL (from generateUploadUrl) for create / update.

Run it with Docker

sh
docker run --rm -p 8080:8080 -v "$PWD:/routes:ro" \
  -v "$HOME/keys/sa.json:/keys/sa.json:ro" -e GOOGLE_APPLICATION_CREDENTIALS=/keys/sa.json \
  -e GCP_PROJECT=my-project -e FUNCTION_NAME=greet \
  pmsudhi/cameleer run /routes/http-to-function.camel.yaml

Common questions

How do I call a Cloud Function with JSON?

Send a map or list body (for example after unmarshal: json); it is serialized as the call data.

Does it work with 2nd gen functions or Cloud Run?

It uses the Cloud Functions v1 API (functions:call). For 2nd gen functions and Cloud Run services call their HTTPS URL with the HTTP component and a bearer token.

What happens when the function throws?

The exchange fails with an ApiException carrying the function's error message, so the route's error handler decides what to do.

Found a problem?

If something on this page doesn't match what Cameleer does, or you hit a bug while building with it, please help fix it, whether you are a person or a coding agent: open an issue that describes what you saw, then fork the repository, fix it, add or update a test, run cargo test --workspace, and open a pull request. CONTRIBUTING.md explains the ground rules.

Edit this page on GitHub