Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Labs

Integrating Google Cloud Functions and Cloud Source Repositories

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 and test that Cloud Function.

Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 30m
Published
Clock icon Mar 01, 2019

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    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.
    3. Use the API Library to find and enable the Google Build API.
  2. Challenge

    Create a Source Repository

    1. From the console, visit the Source Repositories dashboard.
    2. Click Get Started.
    3. Click Create Repository.
    4. Click Create New Repository and then Continue.
    5. On the Create New Repository page, complete these fields:
      • Repository Name: acg-cf-repo.
      • Project: Select the current project.
    6. Click Create.
  3. Challenge

    Clone the Source Repository

    1. Return to the main console page and, from the top right, click Activate Cloud Shell.
    2. Expand the Projects panel by clicking the triangle next to the current project name.
    3. Copy the current project ID.
    4. In the Cloud Shell, enter the following command:

    gcloud config set project <PROJECT_ID>

    1. Enter the following command to clone the repo in the shell environment:
    gcloud source repos clone acg-cf-repo
    
  4. Challenge

    Clone the GitHub Repository

    1. Clone an existing Github repository with the following command:
    git clone https://github.com/linuxacademy/content-gcpro-developer
    
  5. Challenge

    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/* acg-cf-repo

    1. Change to the repo directory:

    cd acg-cf-repo

    1. Configure two variables: user.email and user.name with the following code:
        git config user.name “<USER_NAME>”
        git config user.email “<USER_EMAIL>”
    
    1. Push the files to the Source Repository repository: git add . git commit -m "Initial commit" . git push origin master
    2. Refresh the Source Repository page to confirm the files.
  6. Challenge

    Create a Cloud Function

    1. Using the main navigation menu, under SERVERLESS, click Cloud Functions.
    2. Click CREATE FUNCTION.
    3. Apply the following settings:
      • Name: acg-cf-greetings
      • Region: us-central1
      • Trigger: HTTP
    4. Enable Allow unauthenticated invocations and click SAVE.
    5. In the "Runtime, build, connections and security settings" section, under the RUNTIME tab, choose the "Maximum number of instances" to be 1 (Instead of 3,000).
    6. Click NEXT.
    7. For the Runtime, select Python 3.9.
    8. Change the Source code to Cloud Source repository.
    9. Under Cloud Source repository, change the Repository name to "acg-cf-repo".
    10. For the Entry point, enter "greetings_http".
    11. Click DEPLOY.
  7. Challenge

    Test the Cloud Function

    1. Open the Cloud Function and, from the Trigger tab, click the provided URL.
    2. Confirm the expected result appears.
    3. Add the following argument to the URL: ?name=Joe.
    4. Choose the Testing tab.
    5. In the Triggering event section, insert the following code: {"name":"Joey"}
    6. Click Test the function.
    7. Review the output results.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans