mridul agarwal
mridul agarwal

Reputation: 1

Selecting region for api in google cloud

just want to know the steps to select different region and zones for api in same project on google cloud console. I have already tried setting the default location and region but want to select it everytime api is enabled

Upvotes: 0

Views: 1057

Answers (2)

The default zone and region of compute engine are saved in the metadata, so you should change them or set them from there. You should use the following API: projects.setCommonInstanceMetadata https://cloud.google.com/compute/docs/reference/rest/v1/projects/setCommonInstanceMetadata

Example in node 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();
}

Upvotes: 0

JM Gelilio
JM Gelilio

Reputation: 3768

There is no feature to choose the location of an API but you can set the location/region when creating a instance of every Google Cloud Products or Services like App Engine, Cloud Function, Compute Engine and etc.

Note that the selected location/region of some services like App Engine cannot be changed once you have deployed your app on it. The way to change it is to create a new project and select the preferred location.

If you are pertaining to this documentation about using the changed default location. I believe this is applicable only for Compute Engine resources. I would recommend that you should always check the default region and zone or the selected location settings when creating and managing your resources.

Upvotes: 1

Related Questions