Create a Cloud Run function by using the Google Cloud console

Cloud Run functions is a serverless execution environment for building and connecting cloud services. With Cloud Run 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 an HTTP function using the Google Cloud console. This page is based on Node.js, but the process is similar for all of the runtimes.

The example in this quickstart uses the following Node.js 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 Google Cloud 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 Google Cloud 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 Run functions Overview page

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

  2. Click Create function.

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

  4. Select a Region in which to deploy your function.

  5. In the HTTPS field under Trigger, leave Require authentication selected. This is the default setting.

    The other option, Allow unauthenticated invocations, lets you reach the function without authentication. This is useful for testing, but we don't recommend using this setting in production unless you are creating a public API or website. Further, it might not work for you, depending on your corporate policy settings. See Authenticating for invocation for details on how to invoke a function that requires authentication.

  6. Click Next.

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

  8. Use the Runtime dropdown to select the desired runtime. This example uses nodejs20`.

Deploy the function

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

  2. After clicking Deploy, the Google Cloud console redirects to the Function details page.

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

Test the function

To test the function after it has finished deploying:

  1. Open the Testing tab.

  2. Scroll down to the CLI test command field.

  3. Click Run in Cloud Shell.

    A Cloud Shell window opens at the bottom of your screen, displaying the curl command from the Testing tab. You might be prompted to authorize Cloud Shell.

  4. To execute the curl command that is displayed in your Cloud Shell window, press Return.

    Your "Hello world" message is displayed.

What's next