📖 Scenario: You are building a simple workflow in Google Cloud Workflows to automate a daily task. This workflow will call two services in sequence: first, it will call a mock API to fetch data, then it will call another mock API to process that data.This project will guide you step-by-step to create the workflow definition in YAML format.
🎯 Goal: Create a Google Cloud Workflow YAML file that defines a sequence of two steps: fetchData and processData. Each step calls a mock HTTP endpoint. The workflow should be valid and deployable.
📋 What You'll Learn
Create a workflow named dailyTaskWorkflow with an initial step
Add a configuration variable for the base API URL
Define the fetchData step to call the /fetch endpoint
Define the processData step to call the /process endpoint using data from fetchData
💡 Why This Matters
🌍 Real World
Automating sequences of API calls is common in cloud environments to integrate services without manual intervention.
💼 Career
Understanding how to define and deploy workflows helps in roles like cloud engineer, DevOps, and site reliability engineering.
Progress0 / 4 steps
1
Create the initial workflow structure
Create a workflow YAML named dailyTaskWorkflow with a main sequence that starts with a step called fetchData. The fetchData step should be empty for now.
GCP
Hint
Start by defining main with steps. Add a step named fetchData that calls http.get with empty arguments and stores the result in fetchResponse.
2
Add a configuration variable for the base API URL
Add a variable named baseUrl at the top level of the workflow and set it to "https://mockapi.example.com".
GCP
Hint
Define baseUrl as a top-level variable with the exact URL string.
3
Configure the fetchData step to call the fetch endpoint
Modify the fetchData step to call the URL ${baseUrl}/fetch using http.get. Pass the URL in args.url and store the result in fetchResponse.
GCP
Hint
Use args.url to specify the full URL using the baseUrl variable and the /fetch path.
4
Add the processData step to call the process endpoint with fetched data
Add a new step named processData after fetchData in main.steps. It should call http.post with args.url set to ${baseUrl}/process and args.body set to fetchResponse.body. Store the result in processResponse.
GCP
Hint
Define processData step with call: http.post. Use args.url for the process endpoint and args.body to send the fetched data.
Practice
(1/5)
1. What is the main purpose of Google Cloud Workflows?
easy
A. To store large amounts of data securely
B. To automate and coordinate multiple cloud services in a sequence
C. To create virtual machines for computing
D. To monitor network traffic in real-time
Solution
Step 1: Understand the role of Workflows
Workflows are designed to automate tasks by connecting different cloud services step-by-step.
Step 2: Compare options with this role
Options B, C, and D describe storage, computing, and monitoring, which are not the main purpose of Workflows.
Final Answer:
To automate and coordinate multiple cloud services in a sequence -> Option B
Quick Check:
Workflows automate cloud tasks = A [OK]
Hint: Workflows connect services step-by-step to automate tasks [OK]
Common Mistakes:
Confusing Workflows with storage or compute services
Thinking Workflows monitor network traffic
Assuming Workflows create virtual machines
2. Which of the following is the correct way to start a step in a Google Cloud Workflow YAML?
easy
A. steps:
B. start:
C. main:
D. execute:
Solution
Step 1: Recall the YAML structure for Workflows
The main entry point for a workflow is defined under the main: key.
Step 2: Check other options
Options like steps:, start:, and execute: are not valid top-level keys for starting a workflow.
Final Answer:
main: -> Option C
Quick Check:
Workflow starts with main: in YAML [OK]
Hint: Workflows start with main: block in YAML [OK]
In Workflows YAML, expressions must be wrapped in ${} to be evaluated.
Step 2: Verify other parts
Indentation is correct, http.get is valid, and URL is quoted properly.
Final Answer:
Missing ${} around the expression in return -> Option D
Quick Check:
Expressions need ${} to evaluate in return [OK]
Hint: Wrap expressions in ${} to evaluate in workflow YAML [OK]
Common Mistakes:
Forgetting ${} around expressions
Misaligning YAML indentation
Assuming http.get is invalid
Not quoting URLs
5. You want to create a workflow that calls two APIs in sequence, but only calls the second API if the first returns status "ok". Which workflow feature helps you implement this conditional logic?
hard
A. Using switch or if steps to check the first API's response
B. Using parallel steps to call both APIs at the same time
C. Using retry to repeat the first API call until status is ok
D. Using return to stop the workflow after the first call
Solution
Step 1: Understand conditional execution in workflows
Workflows support switch or if steps to decide which steps run based on conditions.
Step 2: Match the requirement
To call the second API only if the first returns "ok", use if or switch to check the first response before proceeding.
Final Answer:
Using switch or if steps to check the first API's response -> Option A
Quick Check:
Conditional steps use if/switch to control flow [OK]
Hint: Use if or switch to run steps conditionally in workflows [OK]
Common Mistakes:
Using parallel steps which run both APIs simultaneously
Using retry which repeats calls but doesn't conditionally run next
Using return which ends workflow early
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.