
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Create an HTTP function
/ 10
Create a Cloud Storage function
/ 10
Create function revisions
/ 10
Cloud Run functions is the latest version of Google Cloud Run functions, Google Cloud's Functions-as-a-Service offering. This version comes with an advanced feature set and is powered by Cloud Run and Eventarc, giving you more advanced control over performance and scalability, and more control around the functions runtime and triggers from over 90+ event sources.
In this lab, you create Cloud Run functions that respond to HTTP requests, and event-driven functions that are triggered by Cloud Storage events. You will also deploy multiple revisions of a Cloud Run function and explore new settings.
This new version of Cloud Run functions provides an enhanced FaaS experience powered by Cloud Run, Cloud Build, Artifact Registry, and Eventarc.
In this lab, you:
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Sign in to Qwiklabs using an incognito window.
Note the lab's access time (for example, 1:15:00
), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have to start at the beginning.
When ready, click Start lab.
Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.
Click Open Google Console.
Click Use another account and copy/paste credentials for this lab into the prompts.
If you use other credentials, you'll receive errors or incur charges.
Accept the terms and skip the recovery resource page.
Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud.
Google Cloud Shell provides command-line access to your Google Cloud resources.
In Cloud console, on the top right toolbar, click the Open Cloud Shell button.
Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Example output:
Output:
Example output:
Before you create Cloud Run functions, you must enable the relevant APIs.
Sign in to the Google Cloud console with your lab credentials, and open the Cloud Shell terminal window.
Run the following commands in Cloud Shell to set your Project ID and Region environment variables:
Run the following command to enable all necessary service APIs.
If prompted, click Authorize.
For the first function, you create an authenticated Node.js function that responds to HTTP requests to convert a temperature value from Fahrenheit to Celsius, and respond with the converted temperature value.
To access Cloud Run functions, on the Navigation menu (), click Cloud Run functions.
You are redirected to Cloud Run in the console.
Click Write a Function.
For Service name, type temperature-converter
.
For Region, select the
For Authentication, select Require authentication.
Scroll to the bottom and expand Container(s), Volumes, Networking, Security.
Under Revision scaling, for Maximum number of instances, enter 1.
Leave the remaining settings as their defaults, and click Create.
Our function will be implemented in Node.js. In the Source tab, click on the edit icon next to Base image, select the latest version of the Node.js language runtime, and click Save.
For Function entry point, type convertTemp
.
In the Inline Editor, replace any existing sample code with the following code in the index.js
file:
This is a simple HTTP function in Node.js that converts a temperature value in Fahrenheit or Celsius passed in the request and responds with the converted value.
For more information, view the functions framework documentation.
To deploy the function, click Save and redeploy. Wait until the Cloud Build and underlying Cloud Run service is created.
After the function is deployed, a green check mark is displayed next to the function name in the Cloud Run Services page.
In Cloud Shell, retrieve the HTTP URI of the function and store it in an environment variable:
In Cloud Shell, test the function with the following command:
You should see the following message as a response:
Rerun the command passing in the temperature value in Celsius and the conversion unit:
You should see the following message as a response:
Click Check my progress to verify the objective.
In this task, you create an event-driven function in Node.js that responds to events from a Cloud Storage bucket.
To use Cloud Storage triggers with Cloud Run functions, the Cloud Storage service agent must have the Pub/Sub Publisher (roles/pubsub.publisher
) IAM role on your project.
Cloud Storage functions are based on Pub/Sub notifications from Cloud Storage, and support the finalize
, delete
, archive
, and metadata update
event types.
Set up an environment variable for the Cloud Storage agent's service account:
Grant the Pub/Sub publisher role to the Cloud Storage service agent on your project. A service agent is a Google-managed service account that allows the service to access your resources.
To trigger the function in a later task, you will upload a file to Cloud Storage. Copy this file that contains sample temperature data to your Cloud Shell environment:
In this subtask, you develop a function locally in Cloud Shell. Create a directory and navigate to it:
Create the index.js
and package.json
files for your Node.js function:
In the Cloud Shell toolbar, click Open Editor.
In the editor Explorer, expand the temp-data-checker
folder.
Add the following code to the temp-data-checker/index.js
file:
To specify dependencies and other package information for your Node.js function, add the following content to the temp-data-checker/package.json
file:
In the Cloud Shell terminal window, first set an environment variable for the bucket name:
Create a Cloud Storage bucket to store our temperature data file:
To deploy the function, execute the following command in Cloud Shell:
By specifying the trigger-bucket
, every change to the files in this bucket will trigger function execution.
Verify that the function was deployed successfully.
Test the function by uploading the temperature data file to the Cloud Storage bucket:
Run the following command. You should see information from the received CloudEvent in the logs:
You should see output similar to the following:
Click Check my progress to verify the objective.
Cloud Run functions supports several methods of running your functions outside of Cloud Run functions itself. This is useful during iterative development, pre-deployment testing in local environments, data locality compliance, and multi-cloud deployments.
In this task, you modify an existing HTTP function, develop unit and integration tests, and test the function locally before deploying the function to Cloud Run functions.
To access Cloud Run functions, in the Navigation menu (), click Cloud Run.
To view the details of the temperature-converter function, select it's name.
To view the function source code, click the SOURCE tab.
Click Download ZIP, and save the zip file in a folder on your computer renaming it to function-source.zip
.
In the Cloud Shell toolbar, click the More menu (), and select Upload.
In the Upload dialog, click Choose Files.
Select the zip file from the folder that you downloaded previously, click Open, and then click Upload in the dialog.
After the file is uploaded, in Cloud Shell, run the following command:
Extract the contents of the .zip file:
Let's first add some unit tests to the temperature-convert function.
Create a directory that will contain all the function tests, and the unit test source file:
In the Cloud Shell toolbar, click Open Editor.
In the editor, add the following code to the temp-data-converter/tests/unit.http.test.js
file. The test code creates a mock that wraps HTTP requests and responses and uses Sinon stubs to interpret the responses received from the function.
The fourth test is a negative test that expects the function to return a response status code of 400 (Bad Request), since there is no temperature value passed in the request object.
In the temp-data-converter/package.json
file, update the dependencies for your Node.js function to include the scripts
, and devDependencies
sections:
In the Cloud Shell terminal window, run the following command to first install the function's dependencies:
Execute the unit test:
From the command output, verify that all of the tests passed.
Cloud Run functions supports multiple revisions of a function, enabling you to split traffic between different revisions or roll your function back to a prior revision.
Each time you deploy or redeploy a function, a new revision of the underlying Cloud Run service is automatically created. Revisions are immutable and cannot be modified once they are created. To make changes to a function, you must redeploy it.
In this task, you deploy the HTTP function that you created in the previous task with an environment variable, and use the Google Cloud console to manage traffic between two revisions of the function.
In the Google Cloud console, navigate to the Function details page of the temperature-converter
function.
Click Edit and deploy new revision.
In the Container tab, select the Variables and secrets tab.
To add an environment variable, in the Environment variables section, click Add Variable.
For Name 1, type TEMP_CONVERT_TO
To provide a value for the environment variable, for Value 1, type ctof
Click Deploy.
Wait for the deploy process to complete. After the process is completed, you will have two revisions of the function displayed.
By default, the latest deployed revision receives 100% of traffic to the function. This revision is deployed with an environment variable that instructs the function to convert all temperature values from Celsius to Fahrenheit by default.
In Cloud Shell, to test the function, run the following curl
command with the temp
query parameter value in Celsius:
You should see the following response message from the function:
Click Check my progress to verify the objective.
In this lab, you deployed Cloud Run functions that responded to HTTP requests and Cloud Storage Events. You implemented pre-deployment testing with unit tests for an HTTP function and executed them to verify positive and negative scenarios when calling the function. You also deployed multiple revisions of a function and tested the latest revision to verify the function behavior.
For more information about Cloud Run functions, view the documentation:
Copyright 2025 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one