Configura l'ambiente

Prima di pianificare ed eseguire un cron job, devi configurare il tuo Google Cloud progetto e il tuo ambiente per Cloud Scheduler.

Abilita l'API Cloud Scheduler

Segui le istruzioni riportate di seguito per creare o selezionare un progetto Google Cloud e per abilitare l'API Cloud Scheduler.

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. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  4. To initialize the gcloud CLI, run the following command:

    gcloud init
  5. 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.

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

  7. Enable the Cloud Scheduler API:

    gcloud services enable cloudscheduler.googleapis.com
  8. Install the Google Cloud CLI.

  9. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  10. To initialize the gcloud CLI, run the following command:

    gcloud init
  11. 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.

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

  13. Enable the Cloud Scheduler API:

    gcloud services enable cloudscheduler.googleapis.com

Configura l'autenticazione

Il modo in cui esegui l'autenticazione a Cloud Scheduler dipende dall'interfaccia che utilizzi per accedere all'API e dall'ambiente in cui viene eseguito il codice.

Per maggiori informazioni, consulta Autenticarsi in Cloud Scheduler e Utilizzare l'autenticazione con target HTTP.

Aggiungere un'applicazione App Engine

Se intendi utilizzare una destinazione HTTP App Engine, devi aggiungere un'applicazione App Engine al tuo progetto. Questa app funge sia da posizione del servizio Cloud Scheduler sia da gestore dei job stesso, che esegue il lavoro associato a un job Cloud Scheduler e restituisce una conferma in risposta.

Se vuoi un gestore di job App Engine che non si trovi nel tuo progetto, devi selezionare una destinazione HTTP. In questo caso, non hai bisogno di un'app App Engine nel tuo progetto.

Console

  1. Nella console Google Cloud , vai alla pagina App Engine.

    Vai ad App Engine

  2. Nella finestra di dialogo Benvenuto in App Engine, esegui una delle seguenti operazioni:

    • Se hai già creato un'applicazione App Engine e viene visualizzato il messaggio L'applicazione App Engine è stata creata, puoi saltare i passaggi rimanenti di questa sezione.

      o

    • Se non hai ancora creato un'applicazione App Engine, fai clic su Crea applicazione e continua con i passaggi rimanenti di questa sezione.

  3. Seleziona una regione per la tua applicazione.

    Tieni presente che europe-west e us-central sono chiamati rispettivamente europe-west1 e us-central1 nei comandi Cloud Scheduler.

    Dopo aver impostato una regione per l'app App Engine, non puoi modificarla.

  4. Non selezionare un account di servizio; viene utilizzato il service account predefinito di App Engine.

  5. Fai clic su Avanti.

    L'applicazione è configurata e creata. Questa operazione potrebbe richiedere alcuni minuti.

  6. Non scaricare Cloud SDK. Fai invece clic su Lo farò più tardi.

    Dovresti visualizzare il messaggio L'applicazione App Engine è stata creata.

gcloud

  1. Per creare un'app App Engine, esegui il comando gcloud app create:

    gcloud app create --region=REGION
    

    Sostituisci REGION con la posizione in cui viene eseguita l'app. Tieni presente che europe-west e us-central sono chiamati, rispettivamente, europe-west1 e us-central1 nei comandi Cloud Scheduler.

    Dopo aver impostato una regione per l'app App Engine, non puoi modificarla.

  2. Puoi controllare la regione di un'app esistente con il seguente comando:

    gcloud app describe
    

    locationId indica la regione. Ad esempio: locationId: us-central.