创建 Google Cloud 项目

要将应用部署到 App Engine,您必须创建 Google Cloud 项目和 App Engine 应用资源。

该 Google Cloud 项目是一个顶级容器,用于存放您的 App Engine 应用和其他 Google Cloud 资源。

要启用 App Engine,就必须创建 App Engine 应用资源。App Engine 应用资源定义了要在其中运行网络服务并存储其相关设置、凭据和元数据的区域。每个 Google Cloud 项目只能创建一个 App Engine 应用资源;并且在这些资源创建后,便无法更改所指定的区域。

如果您已有启用了 App Engine 和 Cloud Build API 的 Google Cloud 项目,则可以继续编写 Web 服务

创建 Google Cloud 项目

  1. 登录您的 Google Cloud 账号。如果您是 Google Cloud 新手,请创建一个账号来评估我们的产品在实际场景中的表现。新客户还可获享 $300 赠金,用于运行、测试和部署工作负载。
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. 确保您的 Google Cloud 项目已启用结算功能

  4. 启用 Cloud Build API。

    启用 API

  5. Install the Google Cloud CLI.
  6. To initialize the gcloud CLI, run the following command:

    gcloud init
  7. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  8. 确保您的 Google Cloud 项目已启用结算功能

  9. 启用 Cloud Build API。

    启用 API

  10. Install the Google Cloud CLI.
  11. To initialize the gcloud CLI, run the following command:

    gcloud init
  12. 运行以下 gcloud 命令来启用 App Engine 并创建关联的应用资源。请注意,位置选定之后无法更改。
    gcloud app create

App Engine 位置

App Engine 是区域级的,这意味着运行您的应用的基础架构位于特定区域并由 Google 代管,以使其在该区域内的所有可用区以冗余方式提供。

选择要在哪个区域运行应用时,首先要考虑该区域是否能满足您的延迟时间、可用性或耐用性要求。通常,您可以选择距离应用的用户最近的区域,但也要考虑提供 App Engine 的位置以及应用使用的其他 Google Cloud 产品和服务的位置。跨多个位置使用服务可能会影响应用的延迟时间及其价格

应用的区域一经设置,便无法更改。

如果您已创建 App Engine 应用,则可以通过执行以下任一操作来查看其区域:

后续步骤

现在您的 Google Cloud 项目已设置完毕,您可以开始编写基本的 Web 服务了。