在安排和运行 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.
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.
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-18。"],[],[],null,["# Set up your environment\n\nBefore scheduling and running a cron job, you must set up your Google Cloud\nproject and environment for Cloud Scheduler.\n\nEnable the Cloud Scheduler API\n------------------------------\n\nUse the following instructions to create or select a Google Cloud project\nand to enable the Cloud Scheduler API. \n\n### Console\n\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Cloud Scheduler API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=cloudscheduler.googleapis.com)\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Cloud Scheduler API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=cloudscheduler.googleapis.com)\n\n\u003cbr /\u003e\n\n### gcloud\n\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Cloud Scheduler API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=cloudscheduler.googleapis.com)\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Cloud Scheduler API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=cloudscheduler.googleapis.com)\n\n\u003cbr /\u003e\n\nSet up authentication\n---------------------\n\nHow you authenticate to Cloud Scheduler depends on the interface you\nuse to access the API and the environment where your code is running.\n\nFor more information, see\n[Authenticate to Cloud Scheduler](/scheduler/docs/authentication) and\n[Use authentication with HTTP targets](/scheduler/docs/http-target-auth).\n\nAdd an App Engine application\n-----------------------------\n\nIf you are going to use an App Engine HTTP target, you must add an\n[App Engine application](/appengine/docs/standard/managing-projects-apps-billing)\nto your project. This app serves as both the location of the Cloud Scheduler\nservice and of the job handler itself, which performs the work associated with\na Cloud Scheduler job, and returns an acknowledgement in response.\n\nIf you want to have an App Engine job handler that is **not** in your\nproject, you should select an HTTP target instead. In this case, you don't need\nan App Engine app in your project. \n\n### Console\n\n1. In the Google Cloud console, go to the **App Engine** page.\n\n\n [Go to App Engine](https://console.cloud.google.com/appengine/start)\n\n \u003cbr /\u003e\n\n2. In the **Welcome to App Engine** dialog, do one of the\n following:\n\n - If you have already created an App Engine application and there\n is a **Your App Engine application has been created** message displayed,\n you can then skip the remaining steps in this section.\n\n or\n\n \u003cbr /\u003e\n\n - If you haven't created an App Engine application yet, then click\n **Create application** and continue with the remaining steps in this\n section.\n\n3. Select a [region](/appengine/docs/locations) for your\n application.\n\n Note that `europe-west` and `us-central` are called, respectively,\n `europe-west1` and `us-central1` in Cloud Scheduler commands.\n\n After you set a region for the App Engine app, **you can't change\n it**.\n4. Don't select a service account; the default App Engine service\n account is used.\n\n5. Click **Next**.\n\n The application is configured and created. This can take a couple of\n minutes.\n6. Don't download the Cloud SDK; instead, click **I'll do this later**.\n\n You should see a **Your App Engine application has been created** message.\n\n### gcloud\n\n1. To create an App Engine app, run the\n [`gcloud app create`](/sdk/gcloud/reference/app/create) command:\n\n gcloud app create --region=\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e with the\n [location](/appengine/docs/locations) in which the app runs. Note that\n `europe-west` and `us-central` are called, respectively, `europe-west1`\n and `us-central1` in Cloud Scheduler commands.\n\n After you set a region for the App Engine app, **you can't change\n it**.\n2. You can check the region of an existing app with the following command:\n\n gcloud app describe\n\n The `locationId` indicates the region. For example:\n `locationId: us-central`."]]