All Workflows code samples
This page contains code samples for Workflows. To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.
Connector for Cloud Spanner
Workflows connector that defines the built-in function used to access Cloud Spanner within a workflow.
- Workflows
- Google Cloud
- YAML
Query a BigQuery dataset and write the results to a Sheet spreadsheet using connectors
Queries a BigQuery dataset using the BigQuery API connector and writes the results to a Sheets spreadsheet using the Google Sheets API connector.
- Google Cloud
- Workflows
- YAML
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.
- Workflows
- Google Cloud
- YAML
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.
- Workflows
- Google Cloud
- Python
Conditional jump to a specific step
Jumps to a specific step depending on the value returned by the first step of the workflow.
- Workflows
- Google Cloud
- YAML
Get started with the Cloud Client Libraries for the Workflows API
Demonstrates getting started with the Cloud Client Libraries for Workflows.
- Workflows
- Google Cloud
- C++
- Node JS
- TypeScript
- JavaScript
Retry steps using a default retry policy
Uses a built-in retry policy for HTTP requests.
- Google Cloud
- Workflows
- YAML
Make an external HTTP POST request
Makes a POST request to an external HTTP endpoint.
- Google Cloud
- Workflows
- YAML
Connector for Cloud Scheduler
Workflows connector that defines the built-in function used to access Cloud Scheduler within a workflow.
- Google Cloud
- Workflows
- YAML
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.
- Workflows
- Google Cloud
- YAML
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.
- Google Cloud
- Workflows
- YAML
Connector for BigQuery
Workflows connector that defines the built-in function used to access BigQuery within a workflow.
- Workflows
- Google Cloud
- YAML
Connector for Cloud SQL Admin
Workflows connector that defines the built-in function used to access Cloud SQL Admin within a workflow.
- Google Cloud
- Workflows
- YAML
Deploy a Kubernetes application using Workflows connectors
Create a GKE cluster using the Kubernetes Engine API connector, and create a Kubernetes deployment and service using the Kubernetes API connector.
- Google Cloud
- Workflows
- YAML
Implicitly step to the next workflow step
Executes the steps of a workflow in the order that they appear in the workflow definition.
- Workflows
- Google Cloud
- YAML
Use Google Translate in a for-in loop
Uses the Cloud Translation API connector in a for-in loop.
- Workflows
- Google Cloud
- YAML
Connector for Google Forms
Workflows connector that defines the built-in function used to access Google Forms within a workflow.
- Workflows
- Google Cloud
- YAML
Connector for Batch
Workflows connector that defines the built-in function used to access Batch within a workflow.
- Workflows
- Google Cloud
- YAML
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.
- Google Cloud
- Workflows
- YAML
Load data from Cloud Storage to BigQuery using a workflow
Runs a series of steps to orchestrate loading and then transforming data in BigQuery by calling Cloud Functions.
- Google Cloud
- Workflows
- YAML
Connector for Compute Engine
Workflows connector that defines the built-in function used to access Compute Engine within a workflow.
- Workflows
- Google Cloud
- YAML
Use a for-in loop to iterate through a list
Uses a for-in loop to iterate through a list.
- Google Cloud
- Workflows
- YAML
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.
- Google Cloud
- Workflows
- Java
- Node JS
- JavaScript
- TypeScript
- Python
Connector for Cloud Resource Manager
Workflows connector that defines the built-in function used to access Cloud Resource Manager within a workflow.
- Google Cloud
- Workflows
- YAML
Run a batch translation using the Cloud Translation connector
Runs a batch translation using the Cloud Translation connector.
- Google Cloud
- Workflows
- YAML
Invoke a Cloud Run workload that requires authentication
Makes an authenticated request within a workflow, using OpenID Connect (OIDC) to connect with Cloud Run.
- Workflows
- Google Cloud
- YAML
Deploy a workflow that listens for events
Triggers when a message is published to a Pub/Sub topic or when a file is uploaded to a Cloud Storage bucket; receives the event, retrieves the appropriate callback details from a Firestore database, and then sends an HTTP request to the callback endpoint.
- Google Cloud
- Workflows
- YAML
Connector for Pub/Sub
Workflows connector that defines the built-in function used to access Pub/Sub within a workflow.
- Workflows
- Google Cloud
- YAML
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.
- Google Cloud
- Workflows
- YAML
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.
- Workflows
- Google Cloud
- YAML
Use a simple subworkflow
Implements a simple subworkflow that is defined after the main workflow definition.
- Google Cloud
- Workflows
- YAML
Connector for Application Integration
Workflows connector that defines the built-in function used to access Application Integration within a workflow.
- Google Cloud
- Workflows
- YAML
Create a workflow using Python or Ruby
Creates a workflow using Python or Ruby.
- Workflows
- Google Cloud
- Python
- Go
- Ruby
- Java
- C#
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.
- Workflows
- Google Cloud
- YAML
Write to Firestore through an HTTP request
Makes an authenticated request within a workflow, using OAuth 2.0 to write to Firestore.
- Workflows
- Google Cloud
- YAML
Connector for Google Sheets
Workflows connector that defines the built-in function used to access Google Sheets from within a workflow.
- Workflows
- Google Cloud
- YAML
Connector for Vertex AI
Workflows connector that defines the built-in function used to access Vertex AI within a workflow.
- Google Cloud
- Workflows
- YAML
Connector for Cloud Storage
Workflows connector that defines the built-in function used to access Cloud Storage within a workflow.
- Workflows
- Google Cloud
- YAML
Demonstrate local scope of variable created inside a for loop
Demonstrates how any variable created in a loop does not exist outside of that loop.
- Google Cloud
- Workflows
- YAML
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.
- Workflows
- Google Cloud
- YAML
Connector for Secret Manager
Workflows connector that defines the built-in function used to access Secret Manager within a workflow.
- Google Cloud
- Workflows
- YAML
List workflows using Python or Ruby
Lists workflows using Python or Ruby.
- Workflows
- Google Cloud
- Java
- Go
- Ruby
- C#
- Python
Connector for Kubernetes API
Workflows connector that defines the built-in function used to access the Kubernetes API within a workflow.
- Google Cloud
- Workflows
- YAML
Perform a parallel step using branches
Executes parallel branches concurrently, with the steps in each branch executing sequentially.
- Workflows
- Google Cloud
- YAML
Create a Compute Engine VM instance using the Compute Engine API connector
Calls the Compute Engine API connector to create a Compute Engine VM instance based on specifications collected through Google Forms.
- Workflows
- Google Cloud
- YAML
Retry steps using a custom retry policy for an HTTP status code
Implements a custom retry policy that retries HTTP requests that return an HTTP status code 202.
- Google Cloud
- Workflows
- YAML
Connector for Workflows definitions
Workflows connector that defines the built-in function used to access Workflows definitions.
- Google Cloud
- Workflows
- YAML
Retry after an HTTP 500 error
Implements a custom retry policy that retries HTTP requests that have returned an HTTP 500 status code.
- Workflows
- Google Cloud
- YAML
Deploy your first workflow
Passes the current day of the week as a search term to the Wikipedia API. A list of related Wikipedia articles is returned.
- Google Cloud
- Workflows
- YAML
Run a workflow that executes other workflows in parallel
Uses a parent workflow that invokes a child workflow through a connector. Each iteration of the child workflow is passed an iteration argument. The parent workflow waits for and stores the result of each child workflow execution.
- Google Cloud
- Workflows
- YAML
Connector for Dataflow
Workflows connector that defines the built-in function used to access Dataflow within a workflow.
- Workflows
- Google Cloud
- YAML
Connector for BigQuery Data Transfer
Workflows connector that defines the built-in function used to access BigQuery Data Transfer within a workflow.
- Workflows
- Google Cloud
- YAML
Deploy a workflow from Git using Cloud Build
Create a Cloud Build configuration file that deploys and runs a workflow.
- Google Cloud
- Workflows
- YAML
Define a map
Defines a map (dictionary) that can hold a user-defined structure of variables or lists.
- Google Cloud
- Workflows
- YAML
Run kubectl commands in a workflow
You can run gcloud CLI commands from a Cloud Build step, and you can create that step in Workflows using the Cloud Build connector.
- Google Cloud
- Workflows
- YAML
Run gcloud commands in a workflow
You can run gcloud CLI commands from a Cloud Build step, and you can create that step in Workflows using the Cloud Build connector.
- Google Cloud
- Workflows
- YAML
Connector for Cloud Run
Workflows connector that defines the built-in function used to access Cloud Run within a workflow.
- Google Cloud
- Workflows
- YAML
Connector for Cloud Functions
Workflows connector that defines the built-in function used to access Cloud Functions within a workflow.
- Workflows
- Google Cloud
- YAML
Connector for Cloud Build
Workflows connector that defines the built-in function used to access Cloud Build within a workflow.
- Google Cloud
- Workflows
- YAML
Get a workflow using Python or Ruby.
Gets a workflow using Python or Ruby.
- Google Cloud
- Workflows
- Ruby
- Python
- Go
- C#
- Java
Run multiple queries serially using the connector for BigQuery.
Runs multiple queries serially, one after the other, using the connector for BigQuery.
- Google Cloud
- Workflows
- YAML
Connector for Kubernetes Engine
Workflows connector that defines the built-in function used to access a Kubernetes Engine container-based application within a workflow.
- Workflows
- Google Cloud
- YAML
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.
- Workflows
- Google Cloud
- YAML
Iterate through a list
Uses a combination of conditional jumps, variables, and the len() function to iterate through a list.
- Google Cloud
- Workflows
- YAML
Execute a Cloud Run job that processes event data saved in Cloud Storage
Use Workflows to execute a Cloud Run job as part of a workflow that processes event data saved in Cloud Storage.
- Workflows
- Google Cloud
- YAML
Create and deploy a workflow using Terraform
Creates and deploys a sample workflow using Terraform.
- Google Cloud
- Workflows
- Terraform
Calculate math floor
After receiving an HTTP request, extracts input from the JSON body, calculates its math.floor, and returns the result.
- Workflows
- Google Cloud
- Python
Connector for Cloud Translation
Workflows connector that defines the built-in function used to access Cloud Translation within a workflow.
- Workflows
- Google Cloud
- YAML
Translate text using the Cloud Translation API
Makes an HTTP POST request to the Cloud Translation API to translate text from English to Russian.
- Workflows
- Google Cloud
- YAML
Use a Cloud Tasks queue to buffer your workflow executions
Creates and adds a large number of tasks to the Cloud Tasks queue to execute a child workflow.
- Workflows
- Google Cloud
- YAML
Connector for Firestore
Workflows connector that defines the built-in function used to access Firestore within a workflow.
- Workflows
- Google Cloud
- YAML
Connector for AI Platform Training and Prediction
Workflows connector that defines the built-in function used to access VertexAI (AI Platform) within a workflow.
- Google Cloud
- Workflows
- YAML
Handle errors with custom predicate
Defines a custom error handler, including a custom predicate and custom backoff parameters.
- Google Cloud
- Workflows
- YAML
Connector for Firestore (read)
Reads from Firestore using a Workflows connector.
- Workflows
- Google Cloud
- YAML
Perform a parallel for:range loop
Uses a parallel for:range loop to translate text, specifying the beginning and end of an iteration range.
- Google Cloud
- Workflows
- YAML
Delete a workflow using Python or Ruby.
Deletes a workflow using Python or Ruby.
- Workflows
- Google Cloud
- Ruby
- Python
- C#
- Go
- Java
Perform error handling in a parallel step
Uses a try/except structure for error handling in a parallel step.
- Workflows
- Google Cloud
- YAML
Input a search term and pass it to an API
Uses your Google Cloud location to construct a search term or you can input your own search term to pass to the Wikipedia API. A list of related Wikipedia articles is returned.
- Workflows
- Google Cloud
- YAML
Connector for Workflows executions
Workflows connector that defines the built-in function used to access Workflows executions.
- Google Cloud
- Workflows
- YAML
Explicitly step to the next workflow step
Uses the next: command to explicitly define the sequence of workflow steps and executes steps in a different order than they appear in the workflow definition.
- Google Cloud
- Workflows
- YAML
Assign variables
Assigns string and number values to variables. Variable assignments are executed sequentially.
- Google Cloud
- Workflows
- YAML
Use an expression to assign a variable value
Uses an expression to assign the value of a variable previously defined.
- Google Cloud
- Workflows
- YAML
Perform a parallel for:in loop
Uses a parallel for:in loop to translate text.
- Workflows
- Google Cloud
- YAML
Update a workflow using Python or Ruby
Updates a workflow using Python or Ruby.
- Google Cloud
- Workflows
- Python
- Java
- C#
- Go
- Ruby
Store callback details in a Firestore database
Stores callback details in a Firestore database, halts execution, and then waits for specific events to occur.
- Workflows
- Google Cloud
- YAML
Connector for Transcoder
Workflows connector that defines the built-in function used to access Transcoder within a workflow.
- Google Cloud
- Workflows
- YAML
Create a workflow that executes a Cloud Run job using Terraform
Deploys a sample workflow using Terraform.
- Google Cloud
- Workflows
- Terraform
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.
- Google Cloud
- Workflows
- YAML
Connector for Cloud Natural Language
Workflows connector that defines the built-in function used to access Cloud Natural Language within a workflow.
- Google Cloud
- Workflows
- YAML
Write to Google Sheets from a workflow
Uses the Google Sheets API connector to create a spreadsheet.
- Google Cloud
- Workflows
- YAML
Multiply a number 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.
- Workflows
- Google Cloud
- Python
Use a for-range loop to make HTTP requests
Uses range-based iteration to make HTTP requests.
- Google Cloud
- Workflows
- YAML
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.
- Workflows
- Google Cloud
- YAML
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.
- Workflows
- Google Cloud
- YAML
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.
- Workflows
- Google Cloud
- YAML
Connector for Document AI
Workflows connector that defines the built-in function used to access Document AI within a workflow.
- Workflows
- Google Cloud
- YAML
Execute other workflows in parallel
Run a workflow that executes other workflows in parallel.
- Workflows
- Google Cloud
- YAML
Make an external HTTP GET request with headers
Makes an HTTP GET request with a custom header.
- Google Cloud
- Workflows
- YAML
Connector for Storage Transfer Service
Workflows connector that defines the built-in function used to access Storage Transfer Service within a workflow.
- Google Cloud
- Workflows
- YAML
Use a for-in loop to iterate through a map
Uses a for-in loop to iterate through a map.
- Workflows
- Google Cloud
- YAML
Connector for Firestore (write)
Writes to Firestore using a Workflows connector.
- Google Cloud
- Workflows
- YAML
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.
- Google Cloud
- Workflows
- YAML
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.
- Workflows
- Google Cloud
- YAML
Connector for Cloud Tasks
Workflows connector that defines the built-in function used to access Cloud Tasks within a workflow.
- Google Cloud
- Workflows
- YAML