Integrating Google Cloud Functions

30 minutes
  • 7 Learning Objectives

About this Hands-on Lab

Increasingly, organizations find that breaking down their monolithic applications into a series of microservices — which can scale effortlessly — is a viable programming model. Google Cloud Functions are event-driven, serverless functions that can be triggered either directly by an HTTP call (with or without arguments, in a variety of formats) or by specific occurrences, such as a file being uploaded to a targeted Cloud Storage bucket. In this hands-on lab, you’ll lay the groundwork for managing the Cloud Functions source code in a Google Cloud Source Repository and then deploy that Cloud Function.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Enable required APIs.
  1. Use the API Library to find and enable the Google Cloud Source Repository API.
  2. Use the API Library to find and enable the Google Cloud Functions API.
Create a source repository.
  1. From the console, visit the Source Repositories dashboard.
  2. Click Add Repository and follow the steps:
    • Choose Create a New Repository.
    • Select the current project.
Clone the source repository.

Use the following command:

 gcloud source repos clone la-cf-repo
Clone the GitHub repository.

From the Cloud Shell, issue the following command to clone the repository for this course:

git clone
Copy and push the files to the source repository repo.
  1. Copy the files to the source repository with the following command:
    cp content-gcpro-developer/cloud-functions-lab/* la-cf-repo

  2. Change to the repo directory:
    cd la-cf-repo

  3. Configure two variables: and

  4. Push the files to the Source Repository repository:
    git add .
    git commit -m "Initial commit" .
    git push origin master

  5. Refresh the Source Repository page to confirm the files.

Create a Cloud Function.
  1. Navigate to the Cloud Functions dashboard.
  2. Click Create function.
  3. Apply the following settings:
    • Name: la-cf-greetings
    • Trigger: HTTP
    • Allow unauthenticated invovations: Checked
    • Source Code: Cloud Source Repository
    • Runtime: Python 3.7
    • Repository: la-cf-repo
    • Function to execute: greetings_http
  4. Expand Environment Variables, Networking, Timeouts and More and, from the Service Accounts list, choose Compute Engine default service account.
  5. Click Create.
Test the Cloud Function.
  1. Open the Cloud Function and, from the Trigger tab, copy the provided URL.
  2. In a new browser tab, paste the URL and add the following argument: ?name=Joe.
  3. Choose the Testing tab.
  4. In the Triggering event section, insert the following code:
  5. Click Test the function.

Additional Resources

You’ve been asked to lay the groundwork for your company's new microservice by deploying an example Cloud Function. Because the Cloud Function will be worked on by the development team, the source code will need to be stored in a source repository. The microservice will be triggered by an HTTP call that passes in an argument contained in either a JSON file or passed as a URL argument, so your work will need to demonstrate both capabilities.

To accomplish this task, you’ll need to complete the following steps:

  1. Enable the necessary APIs.
  2. Create a new source repository.
  3. Clone an existing repository.
  4. Push the code from the cloned repository into the new repository.
  5. Create the Cloud Function.
  6. Test the Cloud Function.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?