Stay organized with collections Save and categorize content based on your preferences.

Console Quickstart for Cloud Functions (2nd gen)

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. Your function is triggered when an event being watched is fired, or by an HTTP request.

This page shows how to create and deploy a 2nd gen HTTP function using the Google Cloud console. This page is based on Node.js, but the process is similar for all of the runtimes.

This example uses the following function, which returns a message when triggered by an HTTP request:

const functions = require('@google-cloud/functions-framework');

functions.http('helloHttp', (req, res) => {
 res.send(`Hello ${req.query.name || req.body.name || 'World'}!`);
});

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.

  4. Enable the Cloud Functions, Cloud Build, Artifact Registry, Cloud Run, Logging, and Pub/Sub APIs.

    Enable the APIs

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.

  7. Enable the Cloud Functions, Cloud Build, Artifact Registry, Cloud Run, Logging, and Pub/Sub APIs.

    Enable the APIs

Create a function

  1. Open the Functions Overview page in the Google Cloud console:

    Go to the Cloud Functions Overview page

    Make sure that the project for which you enabled Cloud Functions is selected.

  2. Click Create function.

  3. For the Environment, select 2nd gen.

  4. Name your function, for example, function-1.

    The name you give your function can include lowercase letters, numbers, and hyphens. Cloud Functions (2nd gen) does not support capital letters in function names.

  5. In the Authentication field, select Allow unauthenticated invocations.

  6. Click Next.

  7. In the Source code field, select Inline editor. In this exercise, you will use the default function provided in the editor.

  8. Use the Runtime dropdown to select the desired runtime. This example uses Node.js 16.

Deploy the function

  1. At the bottom of the page, click Deploy.

  2. After clicking Deploy, the Google Cloud console redirects to the Cloud Functions Overview page.

    While the function is being deployed, the icon next to it is a small spinner. After it finishes deploying, the spinner turns to a green check mark:

    Screenshot that shows function deployment process

Test the function

To test the function:

  1. Click the linked name of the function in the Cloud Functions Overview page to open the Function details page.

  2. Open the Trigger tab to find your function's URL link.

  3. Open the URL to see a web browser displaying the message "Hello World!"

What's next