Quickstart: Using the gcloud Command-Line Tool

This page shows you how to create and deploy a Cloud Function using the gcloud command-line tool.

Before you begin

  1. Sign in to your Google account.

    If you don't already have one, sign up for a new account.

  2. Select or create a Cloud Platform project.

    Go to the Manage resources page

  3. Enable billing for your project.

    Enable billing

  4. Enable the Cloud Functions API.

    Enable the API

  5. Install and initialize the Cloud SDK.
  6. Update and install gcloud components:
    gcloud components update &&
    gcloud components install beta
  7. Need a command prompt? You can use the Google Cloud Shell. The Google Cloud Shell is a command line environment that already includes the Google Cloud SDK, so you don't need to install it. (The Google Cloud SDK also comes preinstalled on Google Compute Engine Virtual Machines.)

  8. Prepare your environment for Node.js development.

    Go to the setup guide

Create a function

  1. Create a directory on your local system for the function code:

    Linux or Mac OS X

    Create the directory:

    mkdir ~/gcf_hello_world

    Move into the directory:

    cd ~/gcf_hello_world


    Create the directory:

    mkdir %HOMEDRIVE%%HOMEPATH%\gcf_hello_world

    Move into the directory:

    cd %HOMEDRIVE%%HOMEPATH%\gcf_hello_world

  2. Create an index.js file in the gcf_hello_world directory with the following contents. This is a simple function named helloGET that responds to GET requests via HTTP with the text "Hello World!".


     * HTTP Cloud Function.
     * @param {Object} req Cloud Function request context.
     * @param {Object} res Cloud Function response context.
    exports.helloGET = (req, res) => {
      res.send('Hello World!');

Deploy a function

Deploy the function using the following command. Note that it might take a few minutes to finish.

gcloud beta functions deploy helloGET --trigger-http

Test the function

  1. When the function finishes deploying, take note of the httpsTrigger's url property or find it using the following command:

    gcloud beta functions describe helloGET
    It should look like this: https://[GCP_REGION]-[PROJECT_ID].cloudfunctions.net/helloGET.

  2. Visit this URL in your browser. You should see a Hello World! message.

What's next

Send feedback about...

Cloud Functions Documentation