Set up your environment

Before scheduling and running a cron job, you must set up your Google Cloud project and environment for Cloud Scheduler.

Enable the Cloud Scheduler API

Use the following instructions to create or select a Google Cloud project and to enable the Cloud Scheduler API.

Console

  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 Scheduler API.

    Enable the API

  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 Scheduler API.

    Enable the API

gcloud

  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. Install the Google Cloud CLI.
  3. To initialize the gcloud CLI, run the following command:

    gcloud init
  4. Create or select a Google Cloud project.

    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  5. Make sure that billing is enabled for your Google Cloud project.

  6. Enable the Cloud Scheduler API:

    gcloud services enable scheduler.googleapis.com
  7. Install the Google Cloud CLI.
  8. To initialize the gcloud CLI, run the following command:

    gcloud init
  9. Create or select a Google Cloud project.

    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  10. Make sure that billing is enabled for your Google Cloud project.

  11. Enable the Cloud Scheduler API:

    gcloud services enable scheduler.googleapis.com

Set up authentication

How you authenticate to Cloud Scheduler depends on the interface you use to access the API and the environment where your code is running.

For more information, see Authenticate to Cloud Scheduler and Use authentication with HTTP targets.

Add an App Engine application

If you are going to use an App Engine HTTP target, you must add an App Engine application to your project. This app serves as both the location of the Cloud Scheduler service and of the job handler itself, which performs the work associated with a Cloud Scheduler job, and returns an acknowledgement in response.

If you want to have an App Engine job handler that is not in your project, you should select an HTTP target instead. In this case, you don't need an App Engine app in your project.

Console

  1. In the Google Cloud console, go to the App Engine page.

    Go to App Engine

  2. In the Welcome to App Engine dialog, do one of the following:

    • If you have already created an App Engine application and there is a Your App Engine application has been created message displayed, you can then skip the remaining steps in this section.

      or

    • If you haven't created an App Engine application yet, then click Create application and continue with the remaining steps in this section.

  3. Select a region for your application.

    Note that europe-west and us-central are called, respectively, europe-west1 and us-central1 in Cloud Scheduler commands.

    After you set a region for the App Engine app, you can't change it.

  4. Don't select a service account; the default App Engine service account is used.

  5. Click Next.

    The application is configured and created. This can take a couple of minutes.

  6. Don't download the Cloud SDK; instead, click I'll do this later.

    You should see a Your App Engine application has been created message.

gcloud

  1. To create an App Engine app, run the gcloud app create command:

    gcloud app create --region=REGION
    

    Replace REGION with the location in which the app runs. Note that europe-west and us-central are called, respectively, europe-west1 and us-central1 in Cloud Scheduler commands.

    After you set a region for the App Engine app, you can't change it.

  2. You can check the region of an existing app with the following command:

    gcloud app describe
    

    The locationId indicates the region. For example: locationId: us-central.