
Introduction
Google Workflow was first introduced on August 25, 2020. It is a platform that serves as a serverless workflow for developers to orchestrate and automates Google Cloud and connects a series of HTTP-based API services. For example, you can use Google Workflow to connect a Cloud Run Microservice, Cloud Functions, an external API, etc.
A workflow is built by a series of steps that specified the functions to be performed at each step and is written in YAML or JSON format. After finish creating the workflow, you will need to deploy the workflow before it can be executed. Upon execution, it will run based on the logic specified in the workflow created.
In this article, let’s learn how to use Google Cloud Workflow – I will provide examples of how to perform a specific task on Google Workflow by covering the following items:
(1) Print a "Hello World" Message
(2) Calling an HTTP endpoint / API / Microservice
(3) Looping and Iterating with Arrays and Dictionaries
(4) Adding logs to a workflow
Let’s Begin:
If this is your first time accessing Google Workflow, you will need to enable the API.

After workflow API has been enabled, you can create a new workflow. Select "CREATE" to create your first workflow:

Click the button "NEXT" and you can start to define your workflow.
(1) Print a "Hello World" Message
Let’s start with the basics by creating a "Hello World" message to be returned. We will need to define a step that will return our message. Below is how we are going to define:
- returnHelloWorld:
return: "Hello World"

Once you are done with defining the workflow, click the button "DEPLOY" to deploy the workflow and then execute it. You will notice if there is no error, your workflow has been executed successfully with the output message "Hello World".

Congratulation! You have created your first workflow. Let’s move on and see how we can call API endpoints from Google workflow.
(2) Calling an HTTP endpoint / API / Microservice
Now, we will build a step that calls an HTTP endpoint. Common HTTP request methods are "GET’ and "POST". But in this example here we will try on an "HTTP.GET" request using a Cloud Run microservice that has been deployed. We can retrieve the Cloud Run URL from the deployed service details.

This Cloud Run microservice uses a GET method and requires an input to be passed. In this example, an input "AZ" (state- Arizona) will be passed to the service and it will return a message with a value on the total covid-19 cases in the state. (This data set is a COVID-19 Public Datasets retrieves under Google BigQuery Data set program with the date range from May 2020 to October 2020)

As you can see in the image above, the cloud run service will return the total covid-19 cases in the state of Arizona in JSON format. Now, to call this service from Google workflow we will need to create a step (getMicroservice) with a call attribute to "http.get" and the URL will need to be specified under the arguments.
- getMicroservice:
call: http.get
args:
url: https://microservicesexample1-3wv4vbmeja-as.a.run.app/state/AZ
result: state_result
- returnResult:
return: ${state_result.body}

Notice in the last step (returnResult), we retrieve the body of the return message from our HTTP endpoint. The return message will be in JSON format as to how it was specified and return from the Cloud Run microservice.

Well done! You now understand how to call a URL in Google Workflow. Let’s move on and see how we can create loops and iterations by iterating over a list of array values.
(3) Looping and Iterating with Arrays and Dictionaries
In this example, we will create loops and iteration which will iterate through a defined array list and pass the array value to an HTTP endpoint and trigger the HTTP endpoint multiple times with different input values. In the previous step, we only pass the input value for "Arizona(AZ)", whereas there are other states in the data set. Let’s see how we can create an array list for multiple states and pass this value to call the HTTP endpoint via multiple iterations. We will create an array list to call "Arizona (AZ), California (CA), Florida (FA)".
- define:
assign:
- array: ['AZ','CA','FL']
- result: ""
- i: 0
- checkCondition:
switch:
- condition: ${i<len(array)}
next: iterate
next: returnResult
- iterate:
steps:
- getMicroservice:
call: http.get
args:
url: ${"https://microservicesexample1-3wv4vbmeja-as.a.run.app/state/"+array[i]}
result: state_result
- assign_loop:
assign:
- i: ${i+1}
next: checkCondition
- returnResult:
return: ${"Result has been Successfully executed"}
Notice, there is a step called (checkCondition) for deciding when the loop should ends. If the loop condition is true it will pass the array value to the step (iterate). Under the step( iterate), the array value will be passed as an input value to the HTTP endpoint "+array[i]". After finish iterating the values in the array list, the loop will then end and move to the final step (returnResult).

Good job! You have now understood how to create a loop and iterate with an array list. Next, we would like to add logs to know whats is happening in each loop.
(4) Adding logs to a workflow
In Google workflow, there are built-in logging functions that we can add to the workflow to create more visibility on what is happening. For example, in our previous case, we would like to know which Array value is passed in each loop and what are the values. Let’s add this additional log step into our workflow.
- define:
assign:
- array: ['AZ','CA','FL']
- result: ""
- i: 0
- checkCondition:
switch:
- condition: ${i<len(array)}
next: iterate
next: returnResult
- iterate:
steps:
- logstep-1:
call: sys.log
args:
text: ${"Job is running for " + array[i]}
severity: INFO
- getMicroservice:
call: http.get
args:
url: ${"https://microservicesexample1-3wv4vbmeja-as.a.run.app/state/"+array[i]}
result: state_result
- logstep-2:
call: sys.log
args:
text: ${"Result for State " + array[i] + " total is " + state_result.body.Total}
severity: INFO
- assign_loop:
assign:
- i: ${i+1}
next: checkCondition
- returnResult:
return: ${"Result has been Successfully executed"}
To add logs into the workflow, just add a new step and a call to the function "sys.log". In the example create, there are several options on the severity such as INFO, WARNING, CRITICAL, etc. Notice in the visualization below, the logs step is added as part of the iteration to loop. Therefore, the logs will then print what’s happening at each iteration.

The logs can be viewed by navigating to the logs tab. Let’s view what’s printed on our logs:

As we can see from the logs, we know that the first iteration that was run is for Arizona (AZ) and the total cases are 140471. The subsequent iteration details are also printed out in the logs. Adding logs does provide better clarity on what’s happening in the workflow.
Conclusion:
Google workflow is a suitable platform when you have multiple services that you need to manage, such as processing a sequence of events / APIs. In addition, it is easy to manage as no infrastructure is required and the platform scaled on demand. There are other features available in Google Workflow that are not cover in this article such as Error Handling, retry steps, Sleep function, etc. Nonetheless, I hope this article provides a good understanding of how you can create a workflow on Google Cloud.
References & Links:
[1] https://cloud.google.com/workflows/docs
[2] https://cloud.google.com/workflows/docs/reference/stdlib/sys/log
[3] https://atamel.dev/posts/2020/09-08_first_look_at_workflows/