---
title: "GCP Cloud Functions Customize Your Serverless Workflow"
description: "Learn how to build and deploy scalable, serverless applications using GCP Cloud Functions. This tutorial covers essential concepts and best practices for streamlined workflows."
canonical: "https://adamtheautomator.com/gcp-cloud-functions/"
---

# GCP Cloud Functions Customize Your Serverless Workflow

> Learn how to build and deploy scalable, serverless applications using GCP Cloud Functions. This tutorial covers essential concepts and best practices for streamlined workflows.

Source: https://adamtheautomator.com/gcp-cloud-functions/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![GCP Cloud Functions Customize Your Serverless Workflow](https://adamtheautomator.com/wp-content/uploads/2022/12/gcp-cloud-functions.jpg)

# GCP Cloud Functions Customize Your Serverless Workflow

[![](https://secure.gravatar.com/avatar/2788bb1a3f735603f81eca51d68daec56a9d97e805a10268fb2c20afcc76b81b?s=192&d=mm&r=g)Nicholas Xuan Nguyen](https://adamtheautomator.com/author/nicholas-xuan-nguyen/)28 March 20245 min. read

Categories: [DevOps](/category/devops/)

Tags:[Google Cloud](/tag/google-cloud/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Creating a Google Cloud Project](#creating-a-google-cloud-project)
*   [Enabling the GCP Cloud Functions APIs](#enabling-the-gcp-cloud-functions-apis)
*   [Creating and Deploying a GCP Cloud Functions](#creating-and-deploying-a-gcp-cloud-functions)
*   [Testing the GCP Cloud Function](#testing-the-gcp-cloud-function)
*   [Cleaning Up Resources](#cleaning-up-resources)
*   [Conclusion](#conclusion)

Serverless computing is becoming increasingly popular in reducing computing costs and improving scalability. And if you are looking for a serverless environment, Google Cloud Platform (GCP) offers its own in the form of GCP Cloud Functions.

Why stress yourself out worrying about infrastructure when you can focus on building applications instead? Let GCP Cloud Functions handle the rest! In this tutorial, you will learn how to create your first serverless function with GCP Cloud Functions.

Read on and get those codes running without relying on a server!

## Prerequisites

This tutorial will be a hands-on demonstration. To follow along, ensure you have a GCP account and access to the GCP Console. The [free trial](https://cloud.google.com/free) account should be sufficient for this tutorial.

## Creating a Google Cloud Project

Before setting up a serverless environment in GCP, your first step is to create a Google Cloud project. A project is an organizational unit in GCP that contains related services and resources. Every GCP service will be associated with one or more projects.

> 💡 _Creating a new project for each application you develop is strongly recommended. Using existing projects can make managing resources confusing._

To create a Google Cloud project, follow these steps:

1\. Open your favorite web browser, and navigate to the [cloud resource manager](https://console.cloud.google.com/cloud-resource-manager) in the GCP Console.

2\. Next, click **CREATE PROJECT**, as shown below, to create a new project.

![ Creating a new Google Cloud project](https://adamtheautomator.com/wp-content/uploads/2022/12/image-121.png)

Creating a new Google Cloud project

3\. On the next screen, configure the new project with the following:

*   **Project name** – Provide a unique name for the project (i.e., **GCP-cloud-functions-project).Project ID** – GCP will generate a unique ID for your project automatically, and it cannot be changed later. This tutorial goes with the pre-generated ID, but if you prefer a different one, click on **EDIT** and provide a custom project ID.**Location** – Select your preferred parent organization or folder for your project if you have one.

Once filled up, click the **CREATE** button to create your project.

![Creating a new Google Cloud project ](https://adamtheautomator.com/wp-content/uploads/2022/12/image-122.png)

Creating a new Google Cloud project

Once completed, you will receive a notification indicating that you have successfully created the project.

![Confirming the project creation is successful ](https://adamtheautomator.com/wp-content/uploads/2022/12/image-123.png)

Confirming the project creation is successful

You will also see the newly-created project listed in the projects list, as shown below.

![Viewing the newly-created project](https://adamtheautomator.com/wp-content/uploads/2022/12/image-124.png)

Viewing the newly-created project

4\. Now, navigate to the [project selector](https://console.cloud.google.com/projectselector2/home/dashboard) and select your newly created project as the current project.

![Selecting the current project](https://adamtheautomator.com/wp-content/uploads/2022/12/image-125.png)

Selecting the current project

## Enabling the GCP Cloud Functions APIs

Before creating a cloud function, you will have to enable the required APIs. Enabling the APIs will grant permission to access and use the services.

Navigate to [Enable API page](https://console.cloud.google.com/flows/enableapi?apiid=cloudfunctions,cloudbuild.googleapis.com,artifactregistry.googleapis.com,run.googleapis.com,logging.googleapis.com,pubsub.googleapis.com&redirect=https://cloud.google.com/functions/docs/create-deploy-nodejs) for Google Cloud Functions, and click **Next** to confirm making the changes to your project.

![Confirming making changes to the project/](https://adamtheautomator.com/wp-content/uploads/2022/12/image-126.png)

Confirming making changes to the project/

On the next screen, click ENABLE to enable all required APIs, like Cloud Functions API, Cloud Pub/Sub, and others.

![Enabling the required APIs](https://adamtheautomator.com/wp-content/uploads/2022/12/image-127.png)

Enabling the required APIs

Once the required APIs are enabled, you will see a notification like the one below.

![Confirming APIs are successfully enabled](https://adamtheautomator.com/wp-content/uploads/2022/12/image-128.png)

Confirming APIs are successfully enabled

## Creating and Deploying a GCP Cloud Functions

Related:[How to Create an HTTPS NodeJS Web Service with Express](https://adamtheautomator.com/https-nodejs/)

1\. Navigate to the [Functions Overview page](https://console.cloud.google.com/functions/list) in the GCP Console, and click **CREATE FUNCTION** to create a new function.

![Creating a new function](https://adamtheautomator.com/wp-content/uploads/2022/12/image-129.png)

Creating a new function

2\. On the next screen, configure the new function as follows:

<table><tbody><tr><td class="has-text-align-left" data-align="left">Environment</td><td>Select 2nd gen from the dropdown field. GCP offers two versions of Cloud Functions (1st and 2nd Generation). In this tutorial, you will use the 2nd generation since it provides more enhanced features. One of its most notable features is it supports a stable and secure HTTPS endpoint URL.</td></tr><tr><td class="has-text-align-left" data-align="left">Function name</td><td>Provide a unique name for the function (gcp-cloud-functions-1). The name can only contain lowercase letters, numbers, and hyphens.</td></tr><tr><td class="has-text-align-left" data-align="left">Region</td><td>Select a region closest to you from the dropdown field.</td></tr><tr><td class="has-text-align-left" data-align="left">Authentication</td><td>Select the Allow unauthenticated invocations option for testing purposes. This option allows you to trigger the function without complicated authentication.</td></tr></tbody></table>

Keep the other settings as is, and click **Next**.

![Configuring the cloud function](https://adamtheautomator.com/wp-content/uploads/2022/12/image-130.png)

Configuring the cloud function

3\. Configure the code for the function with the following:

*   **Runtime** – Select **Nodejs 16** version from the dropdown field. This runtime version is stable and secure and supports all the latest features of the Node.js language.**Source Code** – Select **Inline Editor** to write the function code.Replace the existing code in the editor with the one below, a basic function to send a “Hello World” output.

```bash
# Imports the functions framework library.
const functions = require('@google-cloud/functions-framework');

# Creates a web endpoint that sends a “Hello World” response when triggered.
functions.http('helloHttp', (req, res) => {
 res.send(`Hello ${req.query.name || req.body.name || 'World'}!`);
});
```

![Configuring code and runtime](https://adamtheautomator.com/wp-content/uploads/2022/12/image-131.png)

Configuring code and runtime

4\. Next, scroll down to the bottom, and click **Deploy** to deploy your Cloud Function, which takes a few seconds to complete.

As you can see, GCP Cloud Functions allows developers like yourself to write code that runs without managing any servers.

![Deploying the GCP Cloud Function](https://adamtheautomator.com/wp-content/uploads/2022/12/image-132.png)

Deploying the GCP Cloud Function

5\. Now, click **REFRESH** to reload the list of deployed functions.

Once the deployment completes, you will see a green checkmark next to the **Environment** column, as shown below. This checkmark indicates your GCP Cloud Functions is active and ready for use.

![Verifying the GCP Cloud Function is active and ready for use](https://adamtheautomator.com/wp-content/uploads/2022/12/image-133.png)

Verifying the GCP Cloud Function is active and ready for use

## Testing the GCP Cloud Function

At this point, you have successfully created and deployed the GCP Cloud Function. But how do you know it is working as expected? You will test your deployed function by navigating to the function’s endpoint URL in your browser.

To test your GCP Cloud Function deployment:

1\. Click the name (hyperlink) of your Cloud Function to open its Overview page.

![Accessing the GCP Cloud Function’s overview page](https://adamtheautomator.com/wp-content/uploads/2022/12/image-134.png)

Accessing the GCP Cloud Function’s overview page

2\. Next, click the copy icon to copy the endpoint URL, as shown below.

![Copying the endpoint URL](https://adamtheautomator.com/wp-content/uploads/2022/12/image-135.png)

Copying the endpoint URL

Navigate to the URL you copied in step three to a new tab in your browser.

If all goes well, you will get the **Hello World** message, as shown below, which indicates your deployed function works.

![Testing the Cloud Function deployment](https://adamtheautomator.com/wp-content/uploads/2022/12/image-136.png)

Testing the Cloud Function deployment

4\. Now, scroll down and view the graphs and charts of the function. These graphs will help you to identify any errors or optimize the performance of the functions. The following screenshots show:

*   The Invocations/Second graph – This graph shows the number of times your function is called every second.

![Viewing the Invocations/Second graph](https://adamtheautomator.com/wp-content/uploads/2022/12/image-137.png)

Viewing the Invocations/Second graph

The Memory utilization (MB/call) graph – This graph shows the average memory used by your function with each invocation. Many more [helpful graphs are available](https://stackoverflow.com/questions/58893997/gcp-cloud-functions-graphs), such as Memory usage, Duration time, and Error rate. Feel free to explore them.

![Viewing the Memory utilization(MB/call) graph](https://adamtheautomator.com/wp-content/uploads/2022/12/image-138.png)

Viewing the Memory utilization(MB/call) graph

## Cleaning Up Resources

Now you have tested your deployment works, ensure you avoid incurring charges by cleaning up your resources.

1\. Navigate to the [cloud resource manager](https://console.cloud.google.com/cloud-resource-manager) page in the GCP Console.

2\. Tick the checkbox next to your project name, and click **DELETE** to delete the selected project. This action deletes all associated resources of your project, such as cloud functions, APIs, and so on.

![Deleting a GCP project](https://adamtheautomator.com/wp-content/uploads/2022/12/image-139.png)

Deleting a GCP project

3\. Finally, enter the project ID when prompted, and click **SHUT DOWN** to confirm the deletion.

You have a grace period of 30 days to undo the deletion. But beyond that period, your project and all its resources get permanently deleted.

![Confirming GCP project deletion](https://adamtheautomator.com/wp-content/uploads/2022/12/image-140.png)

Confirming GCP project deletion

## Conclusion

Serverless computing provides a cost-effective way to develop and scale applications. GCP Cloud Function and [AWS Lambda](https://adamtheautomator.com/aws-lambda-python/) are the two major competitors in cloud technology. And in this tutorial, you have learned how to create and deploy a basic GCP Cloud Function via GCP.

Related:[Building Your First AWS Lambda Python Function](https://adamtheautomator.com/aws-lambda-python/)

You can use these technologies to quickly deploy code and build powerful applications without server management involved.

With this newfound knowledge, why not [use Terraform to automate creating and deploying cloud functions](https://cloud.google.com/functions/docs/tutorials/terraform)?

Related:[How to Install Terraform on Linux and Windows](https://adamtheautomator.com/install-terraform/)

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fgcp-cloud-functions%2F&text=GCP%20Cloud%20Functions%20Customize%20Your%20Serverless%20Workflow)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fgcp-cloud-functions%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fgcp-cloud-functions%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2023/01/google-cloud-storage-python.jpg)

### [How to Install & Use the Google Cloud Storage Python Client](/google-cloud-storage-python-client/)

Discover how to use the Google Cloud Storage Python client in your projects and make your DevOps pipelines work even better!

![](https://adamtheautomator.com/wp-content/uploads/2022/12/gsutil.jpg)

### [Learning the gsutil Command Through Examples](/gsutil/)

Discover the many uses of the gsutil command and learn through examples how to utilize this command-line tool to make your management job easier!

![](https://adamtheautomator.com/wp-content/uploads/2022/12/gcp-secrets-manager.jpg)

### [Getting Started with GCP Secrets Manager](/gcp-secrets-manager/)

Keep your credentials secure and useful in this getting started guide to the GCP Secrets Manager in the Google Cloud Platform!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
