Create a Cloud Function using GCP Console
In our lab walkthrough series, we go through selected lab exercises on our INE Platform. Subscribe or sign up for a 7-day, risk-free trial with INE and access this lab and a robust library covering the latest in Cyber Security, Networking, Cloud, and Data Science!
Purpose: Google Cloud Functions is a serverless execution environment for building and connecting cloud services. With Cloud Functions you write simple, single-purpose functions that are attached to events emitted from your cloud infrastructure and services. In this article, we will learn how to create a Cloud Function using GCP Console.
Technical difficulty:
| Novice | Beginner | Competent | Proficient | Expert
Lab Scenario
We have set up the below scenario in our INE labs for our students to practice. The screenshots have been taken from our online lab environment.
Lab Link: Create a Cloud Function using GCP Console
Objective
In this lab, you will create a Cloud Function using the GCP console and invoke it.
Solution
Step 1: Choose the Start lab button and then choose Open lab. On the next page, agree to the terms and conditions and select Continue.
You will be presented with access credentials, as shown in the following example. Open the GCP Portal Login link in a new private window or Incognito window.
The URL will take you to the GCP login page. Use the provided credentials to log in.
Step 2: Next, click on Accept on the subsequent page, check the Terms of Service checkbox and click on AGREE AND CONTINUE. (Make sure your country is correct)
Now, we got access to the GCP account, let’s see how to create the Cloud Function!
Step 1: On the next screen, you will be presented with the GCP home page. Now, using the search bar on the top, search for cloud functions and click on the Cloud Functions under Products & Pages.
Step 2: You will be redirected to the Cloud Functions page. Now, click on CREATE FUNCTION and click ENABLE in the subsequent popup.
Step 3: In the Create function page, under the Basics section, select the following options (see the screenshot for reference):
Environment : 1st gen
Function name : "helloWorld"
Region : us-central1
Step 4: Under Trigger section, select the following options (see the screenshot for reference):
Trigger type : HTTP
Authentication : Allow unauthenticated invocations
Leave the rest as default and click Save, click Next to proceed to the Code section.
Step 5: In the Code section, select the following options (see the screenshot for reference):
Runtime : Python 3.9
Source code : inline Editor
Entry point : "hello_world"
Step 6: Now, in the code editor, enter the code as shown in the screenshot and click Deploy.
Step 7: You will be taken back to the Cloud Functions page, and wait for your function to be deployed. You can notice a Green Tick to the left of your function when deployed.
We Successfully built and deployed the Cloud Function.
Now, let’s invoke the Cloud Function.
Step 1: To invoke your function, first, click on the name of your function.
Under the TRIGGER tab, click on Target URL.
Step 2: You can see that the link invokes your function and displays "Hello World!" in a new tab.
Let’s see how to delete the Cloud Function.
Step 1: To delete the function, click on the Delete option, and in the subsequent prompt, click DELETE.
wait for the function to be deleted. Upon deletion, you will be taken back to the Cloud Functions page. Make sure your function is deleted.
Conclusion
Congratulations! In this lab, you created and deleted an Invokable Cloud Function using the GCP console.
Try the GCP console for yourself hands-on! Subscribe or sign up for a 7-day, risk-free trial with INE to access this lab and a robust library covering the latest in Cyber Security, Networking, Cloud, and Data Science!