This page contains code samples for Workflows. To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.
Aggregate data using a parallel loop
Separate queries to a public BigQuery dataset each return the number of words in a document, or set of documents. A shared variable allows the count of the words to accumulate and be read after all the iterations complete.
View in documentation
Calculate math floor
After receiving an HTTP request, extracts input from the JSON body, calculates its math.floor, and returns the result.
Catch errors
Implements a custom exception handler based on the HTTP status code returned by a GET request. The workflow catches a potential exception and returns a predefined error message.
View in documentation
Conditional jump to a specific step
Jumps to a specific step depending on the value returned by the first step of the workflow.
View in documentation
Conditional jump to a specific step
Jumps to a specific step depending on the day of the week returned by the first step of the workflow.
View in documentation
Connector Cloud Resource Manager
Workflows connector that defines the built-in function used to access Cloud Resource Manager within a workflow.
View in documentation
Connector for AI Platform Training and Prediction
Workflows connector that defines the built-in function used to access VertexAI (AI Platform) within a workflow.
View in documentation
Connector for BigQuery
Workflows connector that defines the built-in function used to access BigQuery within a workflow.
View in documentation
Connector for BigQuery Data Transfer
Workflows connector that defines the built-in function used to access BigQuery Data Transfer within a workflow.
View in documentation
Connector for Cloud Build
Workflows connector that defines the built-in function used to access Cloud Build within a workflow.
View in documentation
Connector for Cloud Functions
Workflows connector that defines the built-in function used to access Cloud Functions within a workflow.
View in documentation
Connector for Cloud Natural Language
Workflows connector that defines the built-in function used to access Cloud Natural Language within a workflow.
View in documentation
Connector for Cloud Run
Workflows connector that defines the built-in function used to access Cloud Run within a workflow.
View in documentation
Connector for Cloud Scheduler
Workflows connector that defines the built-in function used to access Cloud Scheduler within a workflow.
View in documentation
Connector for Cloud Spanner
Workflows connector that defines the built-in function used to access Cloud Spanner within a workflow.
View in documentation
Connector for Cloud SQL Admin
Workflows connector that defines the built-in function used to access Cloud SQL Admin within a workflow.
View in documentation
Connector for Cloud Storage
Workflows connector that defines the built-in function used to access Cloud Storage within a workflow.
View in documentation
Connector for Cloud Tasks
Workflows connector that defines the built-in function used to access Cloud Tasks within a workflow.
View in documentation
Connector for Cloud Translation
Workflows connector that defines the built-in function used to access Cloud Translation within a workflow.
View in documentation
Connector for Compute Engine
Workflows connector that defines the built-in function used to access Compute Engine within a workflow.
View in documentation
Connector for Dataflow
Workflows connector that defines the built-in function used to access Dataflow within a workflow.
View in documentation
Connector for Document AI
Workflows connector that defines the built-in function used to access Document AI within a workflow.
View in documentation
Connector for Firestore
Workflows connector that defines the built-in function used to access Firestore within a workflow.
View in documentation
Connector for Kubernetes Engine container
Workflows connector that defines the built-in function used to access a Kubernetes Engine container within a workflow.
View in documentation
Connector for Pub/Sub
Workflows connector that defines the built-in function used to access Pub/Sub within a workflow.
View in documentation
Connector for Secret Manager
Workflows connector that defines the built-in function used to access Secret Manager within a workflow.
Connector for Storage Transfer Service
Workflows connector that defines the built-in function used to access Storage Transfer Service within a workflow.
View in documentation
Connector for Workflows definitions
Workflows connector that defines the built-in function used to access Workflows definitions.
View in documentation
Connector for Workflows executions
Workflows connector that defines the built-in function used to access Workflows executions.
View in documentation
Demonstrate variable scope in a parallel step
Demonstrates the scope of a shared variable, as well as variables that are local to their respective branch scopes.
View in documentation
Generate a random number and return result in JSON
After receiving an HTTP request, this function generates a random number between 1 and 100, and then returns the number in JSON format.
Handle errors with custom predicate
Defines a custom error handler, including a custom predicate and custom backoff parameters.
View in documentation
Invoke a Cloud Run workload that requires authentication
Makes an authenticated request within a workflow, using OpenID Connect (OIDC) to connect with Cloud Run.
View in documentation
Make a call to a sample API
Makes a call to a sample API. The returned day of the week is passed to the Wikipedia API. Relevant articles on Wikipedia about the current day of the week are returned.
View in documentation
View in documentation
Multiply by 2 and return result in JSON
After receiving an HTTP request, this function extracts the input from the JSON body, multiplies it by 2, and returns the result in JSON format.
Paginate a BigQuery result set
Uses a page token to paginate a BigQuery result set and loop through a page of results at a time.
View in documentation
View in documentation
Perform a parallel for:range loop
Uses a parallel for:range loop to translate text, specifying the beginning and end of an iteration range.
View in documentation
View in documentation
Perform a parallel step using branches
Executes parallel branches concurrently, with the steps in each branch executing sequentially.
View in documentation
Perform a parallel step with the secondary workflow inlined
Includes the source code for a secondary workflow directly within the main workflow for easier readability.
View in documentation
Perform error handling in a parallel step
Uses a try/except structure for error handling in a parallel step
View in documentation
Perform operations in parallel using branches
Executes a workflow that has multiple and different sets of steps at the same time by placing them in parallel branches.
View in documentation
Perform parallel iteration using for loops
Executes loop iterations in parallel to reduce the end-to-end execution time. A shared variable is updated in each iteration.
View in documentation
Retry after an HTTP 500 error
Implements a custom retry policy that retries HTTP requests that have returned an HTTP 500 status code.
View in documentation
View in documentation
Retry steps with custom configuration
Uses a standard retry predicate that determines when to perform a retry, and a custom maximum number of retries and backoff parameters.
View in documentation
Run a batch translation using the Cloud Translation connector
Runs a batch translation using the Cloud Translation connector.
Run multiple BigQuery query jobs in parallel
Runs multiple BigQuery query jobs in parallel, demonstrating an improvement in performance when compared to running the jobs serially, one after the other.
View in documentation
Run multiple queries serially using the connector for BigQuery.
Runs multiple queries serially, one after the other, using the connector for BigQuery.
View in documentation
Stop a Compute Engine instance through an HTTP request
Makes an authenticated request within a workflow, using OAuth 2.0 to stop a Compute Engine instance.
Translate text using the Cloud Translation API
Makes an HTTP POST request to the Cloud Translation API to translate text from English to Russian.
Use a simple subworkflow
Implements a simple subworkflow that is defined after the main workflow definition.
View in documentation
Use an embedded switch statement to execute steps
Uses a switch structure to directly execute steps when a condition is met, without jumping to other steps.
View in documentation
Use arguments in a workflow
Accesses runtime arguments passed to the workflow as part of the execution request and declared as a parameter of the main workflow.
View in documentation
Use client libraries to execute a workflow
Use client libraries to execute a workflow. Polls the workflow's execution using exponential backoff until the execution terminates and then prints the results.
View in documentation
Use OIDC to authenticate when making a request to Cloud Functions
Makes an HTTP request using OIDC by adding an auth section to the args section of the workflow's definition, after specifying the URL.
View in documentation
Validate a translation request using a callback endpoint
Validates translation requests by supporting a callback endpoint that waits for HTTP requests to arrive at that endpoint, resuming the execution of the workflow at a later point in time.
View in documentation
Write to Firestore through an HTTP request
Makes an authenticated request within a workflow, using OAuth 2.0 to write to Firestore.