Quickstart: Using the gcloud Command-Line Tool

This page shows you how to create and deploy a Cloud Function written with Node.js, Python, or Go using the gcloud command-line tool.

Before you begin

  1. Faça login na sua Conta do Google.

    Se você ainda não tiver uma, inscreva-se.

  2. Selecione ou crie um projeto do Google Cloud Platform.

    Acessar a página Gerenciar recursos

  3. Verifique se o faturamento foi ativado no projeto do Google Cloud Platform.

    Saiba como ativar o faturamento

  4. Ativar Cloud Functions API.

    Ativar a API

  5. Install and initialize the Cloud SDK.
  6. Update gcloud components:
    gcloud components update
  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 development environment.

Get the sample code

  1. Clone the sample repository to your local machine:


    git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git

    Alternatively, you can download the sample as a zip file and extract it.


    git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git

    Alternatively, you can download the sample as a zip file and extract it.


    git clone https://github.com/GoogleCloudPlatform/golang-samples.git

    Alternatively, you can download the sample as a zip file and extract it.

  2. Change to the directory that contains the Cloud Functions sample code:


    cd nodejs-docs-samples/functions/helloworld/


    cd python-docs-samples/functions/helloworld/


    cd golang-samples/functions/helloworld/

  3. Take a look at the sample code:


     * HTTP Cloud Function.
     * This function is exported by index.js, and is executed when
     * you make an HTTP request to the deployed function's endpoint.
     * @param {Object} req Cloud Function request context.
     *                     More info: https://expressjs.com/en/api.html#req
     * @param {Object} res Cloud Function response context.
     *                     More info: https://expressjs.com/en/api.html#res
    exports.helloGET = (req, res) => {
      res.send('Hello World!');


    def hello_get(request):
        """HTTP Cloud Function.
            request (flask.Request): The request object.
            The response text, or any set of values that can be turned into a
            Response object using `make_response`
        return 'Hello World!'


    // Package helloworld provides a set of Cloud Functions samples.
    package helloworld
    import (
    // HelloGet is an HTTP Cloud Function.
    func HelloGet(w http.ResponseWriter, r *http.Request) {
    	fmt.Fprint(w, "Hello, World!")

Deploy a function

To deploy the function with an HTTP trigger, run the following command in the helloworld directory:

Node.js 8

gcloud functions deploy helloGET --runtime nodejs8 --trigger-http

Node.js 10 (Beta)

gcloud functions deploy helloGET --runtime nodejs10 --trigger-http

Node.js 6 (Deprecated)

gcloud functions deploy helloGET --runtime nodejs6 --trigger-http


gcloud functions deploy hello_get --runtime python37 --trigger-http


gcloud functions deploy HelloGet --runtime go111 --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 functions describe helloGET


    gcloud functions describe hello_get


    gcloud functions describe HelloGet

    It should look like this:







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

What's next

Esta página foi útil? Conte sua opinião sobre:

Enviar comentários sobre…

Cloud Functions Documentation