Step 1: Define environment variables

What you're doing in this step

This section describes how to set several environment variables that are used throughout the documentation (and especially in this configuration tutorial). Google strongly recommends that you use them so that you can enter the commands as shown.

Perform the step

To define environment variables on the command line:

  1. Log in to Cloud by using the following command:
    gcloud auth login

    The command launches a browser window and prompts you to choose an account (if you have more than one). Cloud then prompts you to allow access. You only need to do this once: You will not need to run this command, choose an account, or allow access in the future.

  2. Initialize the Cloud SDK, as described in Initializing Cloud SDK; for example:
    gcloud init

    During SDK initialization, enter or select the ID of the project you created in Prerequisites. Set this project as the default. You will not need to run this command in the future unless you want to change the defaults.

  3. Define the following environment variables for the current project:
    AUTH="Authorization: Bearer $(gcloud auth print-access-token)"
    PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format="value(projectNumber)")


    • AUTH defines the Authentication header with a bearer token. You will use this header when you send HTTP requests to your API proxy.
    • PROJECT_ID is the Cloud project ID that you created as part of the Prerequisites. If you're not sure what your project ID is, use Cloud Console or the gcloud projects list command to find it.
    • PROJECT_NUMBER is the Cloud project number that you created as part of the Prerequisites. This example issues a gcloud command to get the project number for you. Alternatively, you can use the gcloud projects list command to find it.
    • LOCATION is the physical location where your instance is located. Valid values are any Compute Engine region.

      The value of LOCATION can be, but does not have to be, the same as ANALYTICS_REGION. (For eval accounts, use a zone and not a region.)

    • ANALYTICS_REGION is the physical location at which you store your analytics data.

      Valid values are a subset of the Compute Engine regions. Possible values are:

      • asia-northeast1
      • asia-south1
      • europe-west1
      • us-central1
      • us-east1
      • us-west1
      • australia-southeast1
      • europe-west2

      The value of ANALYTICS_REGION does not have to be the same as LOCATION. However, there may be a performance benefit if they are the same. (For eval accounts, specify a region, just as with regular accounts.)

    For example:

    AUTH="Authorization: Bearer $(gcloud auth print-access-token)"

    You will use the variable names, such as "$PROJECT_ID" as string literals in your commands.

  4. (Optional) Check your work by echoing the values you just set. Note that when you want to use a variable in your commands, precede the variable's name with a dollar sign ($).

    The responses to your echo commands should look like the following:

    echo $AUTH
    Authorization: Bearer ya29.a123456678940B63hPSAMPLEsampleKKYVsample0f3pWDWZDuH2-hENkNaTvgZ1PD977TMvv6edBQPJezdHw040880Ol_LoD5ZDkt-i-knizia_KhA9L20sSvztL81-SAMPLE42ELPMASk2_1CxN
    echo $PROJECT_ID
    echo $LOCATION

If you encounter errors during this part of the process, see Troubleshooting.

1 NEXT: Enable APIs 3 4 5 6 7 8