cron ジョブをスケジュールして実行する前に、Cloud Scheduler 用に Google Cloudプロジェクトと環境を設定する必要があります。
Cloud Scheduler API を有効にします
次の手順に沿って、 Google Cloud プロジェクトを作成または選択し、Cloud Scheduler API を有効にします。
コンソール
- 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.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Scheduler API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Scheduler API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles.
gcloud
- 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.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
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.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Scheduler API:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles.gcloud services enable cloudscheduler.googleapis.com
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
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.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Scheduler API:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles.gcloud services enable cloudscheduler.googleapis.com
認証を設定する
Cloud Scheduler に対する認証方法は、API へのアクセスに使用するインターフェースと、コードが実行されている環境によって異なります。
詳細については、Cloud Scheduler に対して認証すると HTTP ターゲットで認証を使用するをご覧ください。
App Engine アプリケーションを追加する
App Engine HTTP ターゲットを使用する場合は、プロジェクトに App Engine アプリケーションを追加する必要があります。このアプリは、Cloud Scheduler サービスの場所とジョブハンドラ自体の両方として機能します。ジョブハンドラは、Cloud Scheduler ジョブに関連付けられた処理を実行し、応答で確認応答を返します。
プロジェクトにない App Engine ジョブ ハンドラを使用する場合は、代わりに HTTP ターゲットを選択する必要があります。この場合、プロジェクトに App Engine アプリは必要ありません。
コンソール
Google Cloud コンソールで、[App Engine] ページに移動します。
[App Engine へようこそ] ダイアログで、次のいずれかを行います。
App Engine アプリケーションをすでに作成していて、[App Engine アプリケーションが作成されました] というメッセージが表示されている場合は、このセクションの残りの手順をスキップできます。
または
App Engine アプリケーションをまだ作成していない場合は、[アプリケーションを作成] をクリックして、このセクションの残りの手順に進みます。
アプリケーションのリージョンを選択します。
europe-west
とus-central
は、Cloud Scheduler コマンドではそれぞれeurope-west1
とus-central1
と呼ばれます。App Engine アプリのリージョンを設定した後は、変更できません。
サービス アカウントを選択しない。デフォルトの App Engine サービス アカウントが使用されます。
[次へ] をクリックします。
アプリケーションが構成され、作成されます。これには数分かかることがあります。
Cloud SDK はダウンロードせずに、[後で行う] をクリックします。
「App Engine アプリケーションが作成されました」というメッセージが表示されます。
gcloud
App Engine アプリを作成するには、
gcloud app create
コマンドを実行します。gcloud app create --region=REGION
REGION
は、アプリが実行されるロケーションに置き換えます。europe-west
とus-central
は、Cloud Scheduler コマンドではそれぞれeurope-west1
とus-central1
と呼ばれます。App Engine アプリのリージョンを設定した後は、変更できません。
次のコマンドで既存のアプリのリージョンを確認できます。
gcloud app describe
locationId
はリージョンを示します。例:locationId: us-central
。