Skip to main content

Integrating Google Cloud Functions

Hands-On Lab


Photo of Joseph Lowery

Joseph Lowery

Google Cloud Training Architect II in Content





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.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Integrating Google Cloud Functions

In this hands-on lab, we’ll lay the groundwork for managing the Cloud Functions source code in a Google Cloud Source Repository and then deploy that Cloud Function.

How to Log in to Google Lab Accounts

On the lab page, right-click Open GCP Console and select the option to open it in a new private browser window (this option will read differently depending on your browser — e.g., in Chrome, it says "Open Link in Incognito Window"). Then, sign in to Google Cloud Platform using the credentials provided on the lab page.

On the Welcome to your new account screen, review the text, and click Accept. In the "Welcome L.A.!" pop-up once you're signed in, check to agree to the terms of service, choose your country of residence, and click Agree and Continue.

You're now logged in to the Google Cloud Platform console.

Integrating Cloud Functions

Now, on to the lab!

Enable required APIs.

  1. Navigate to APIs & Services > Library.
  2. Search for "source repository", select Cloud Source Repositories API, and click Enable.
  3. Navigate back to APIs & Services > Library.
  4. Search for "cloud functions", select Cloud Functions API, and click Enable.

Create a source repository.

  1. Navigate to Source Repositories.
  2. Click Get started and then Create repository.
  3. In the Add a repository screen, choose Create new repository and click Continue.
  4. Give it a Repository name of "la-cf-repo".
  5. Select the existing project.
  6. Click Create.
  7. On the Add code to your repository screen, select Push code from a local Git repository.

Clone the source repository.

  1. Back in the GCP console, click the Activate Cloud Shell icon in the upper right navigation bar.
  2. Click Start Cloud Shell.
  3. Once it's been provisioned, enter the following command:

    gcloud source repos clone la-cf-repo

Clone the GitHub repository.

  1. Still in the Cloud Shell, 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:

    cp content-gcpro-developer/cloud-functions-lab/* la-cf-repo
  2. Change to the repo directory:

    cd la-cf-repo
  3. Configure a variable, using the cloud_user username you were assigned as part of the lab:

    git config --global "<CLOUD_USER>"
  4. Configure a variable, using your name:

    git config --global "<YOUR_NAME>"
  5. Push the files to the source repository. First, include all the files with this command:

    git add .
  6. Commit the files:

    git commit -m "Initial commit" .
  7. Complete pushing them with this command:

    git push origin master
  8. Refresh the Cloud Source Repositories page to confirm the files.

Create a Cloud Function.

  1. Navigate to Cloud Functions.
  2. Click Create function.
  3. Apply the following settings:
    • Name: la-cf-greetings
    • Memory allocated: 256 MB
    • Trigger: HTTP
    • Allow unauthenticated invovations: Checked
    • Source code: Cloud Source repository
    • Runtime: Python 3.7
    • Repository: la-cf-repo
    • Branch / tag: Branch
    • Branch name: master
    • Directory with source code: /
    • 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. Click to open the new function.

  2. In the Trigger tab, copy the provided URL.

  3. In a new browser tab, paste the URL and add the following argument at the end: ?name=Joe.

  4. Back in the console, select the Testing tab.

  5. In the Triggering event section, insert the following code:

  6. Click Test the function.


Congratulations on completing this lab!