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.
Successfully complete this lab by achieving the following learning objectives:
- Enable required APIs.
- Use the API Library to find and enable the Google Cloud Source Repository API.
- Use the API Library to find and enable the Google Cloud Functions API.
- Create a source repository.
- From the console, visit the Source Repositories dashboard.
- 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 https://github.com/linuxacademy/content-gcpro-developer
- Copy and push the files to the source repository repo.
Copy the files to the source repository with the following command:
cp content-gcpro-developer/cloud-functions-lab/* la-cf-repo
Change to the repo directory:
Configure two variables:
Push the files to the Source Repository repository:
git add .
git commit -m "Initial commit" .
git push origin master
Refresh the Source Repository page to confirm the files.
- Create a Cloud Function.
- Navigate to the Cloud Functions dashboard.
- Click Create function.
- Apply the following settings:
- Trigger: HTTP
- Allow unauthenticated invovations: Checked
- Source Code: Cloud Source Repository
- Runtime: Python 3.7
- Function to execute:
- Expand Environment Variables, Networking, Timeouts and More and, from the Service Accounts list, choose Compute Engine default service account.
- Click Create.
- Test the Cloud Function.
- Open the Cloud Function and, from the Trigger tab, copy the provided URL.
- In a new browser tab, paste the URL and add the following argument:
- Choose the Testing tab.
- In the Triggering event section, insert the following code:
- Click Test the function.