【问题标题】:Selecting region for api in google cloud在谷歌云中选择 api 的区域
【发布时间】:2021-02-11 05:09:11
【问题描述】:

只是想知道在谷歌云控制台上为同一项目中的 api 选择不同区域和区域的步骤。 我已经尝试设置默认位置和区域 但每次启用 api 时都想选择它

【问题讨论】:

  • 你能澄清region and zone for API的意思吗?您是指 Google Cloud API 和服务,还是您正在开发的 API?
  • 您想在部分区域(或者甚至仅一个区域)上使用服务/产品吗?
  • 是的,我指的是谷歌云 API

标签: google-cloud-platform cloud


【解决方案1】:

没有选择 API 位置的功能,但您可以在创建每个 Google Cloud 产品或服务(例如 App Engine、Cloud Function、Compute Engine 和etc.)的实例时设置位置/区域

请注意,某些服务(如 App Engine)的选定位置/区域一旦在其上部署应用就无法更改。改变它的方法是创建一个新项目并选择首选位置。

如果您与此 documentation 有关使用更改的默认位置。我相信这仅适用于 Compute Engine 资源。我建议您在创建和管理资源时始终检查默认区域和区域或选定的位置设置。

【讨论】:

    【解决方案2】:

    计算引擎的默认区域和区域保存在元数据中,因此您应该从那里更改或设置它们。 您应该使用以下 API:projects.setCommonInstanceMetadata https://cloud.google.com/compute/docs/reference/rest/v1/projects/setCommonInstanceMetadata

    节点js中的示例:

    async function addDefaultRegion(authClient, projectName) {
      var request = {
        project: projectName + "1",
        resource: {
            "items": [
              {
                "key": "google-compute-default-region",
                "value": "europe-west1"
              }
            ]
        },
        auth: authClient
      };
    
      compute.projects.setCommonInstanceMetadata(request, function(err, response) {
        if (err) {
          console.error(err);
          return;
        }
        console.log(JSON.stringify(response, null, 2));
      });
    };
    
    async function authorize() {
      const auth = new google.auth.GoogleAuth({
          scopes: ['https://www.googleapis.com/auth/cloud-platform']
      });
      return await auth.getClient();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-31
      • 1970-01-01
      相关资源
      最近更新 更多