Google Cloud Tasks: Location 'europe-west1' is not a valid location

Viewed 1026

I am trying to run a Google Cloud Tasks task using a Cloud Function, but I'm hitting an error where any region I try to use is wrong.

The code is basic. All is well until it stops because of the following error:

Error: {"code":3,"message":"Location 'europe-west1' is not a valid location. Use ListLocations to list valid locations.","details":[]}

If I attempt to use, for example, us-central1, it will report:

Error: {"code":3,"message":"Location must equal europe-west1 because the App Engine app that is associated with this project is located in europe-west1","details":[]}

I am using the Google Cloud Tasks API with Node.js for creating a new Task:

const client = new CloudTasksClient({ fallback: true }); 
const parent = client.queuePath(PROJECT, 'europe-west1', QUEUE);

A full example can be found here: https://github.com/googleapis/nodejs-tasks/blob/master/samples/createHttpTaskWithToken.js

The URL called is: ""https://cloudtasks.googleapis.com:443/$rpc/google.cloud.tasks.v2beta3.CloudTasks/CreateTask"

If I run the locations list command, this is the output:

$ gcloud tasks locations list
europe-west1    projects/[project-id]/locations/europe-west1

Edit: Using the REST API (https://cloud.google.com/tasks/docs/reference/rest/v2beta3/projects.locations.queues.tasks/create) with the same configuration works. It may be a bug in the client?

I am really not sure what is wrong with my setup.

Not sure what information would be helpful to debug this, so apologies in advance if there's not enough information.

1 Answers

I realized which the example that you are using is for non App Engine/Cloud functions environments please try the simple example that is in the npm page.

Please check on your package.json that you are defining the latest version of google-cloud/tasks library, at this time it is 1.9.0

You don't need to use a Ouath token within App Engine/ Cloud Functions environments, because are already configured with a service account.

// Imports the Google Cloud Tasks library.
  const {CloudTasksClient} = require('@google-cloud/tasks');

  // Instantiates a client.
  const client = new CloudTasksClient();

  // TODO(developer): Uncomment these lines and replace with your values.
  // const project = 'my-project-id';
  // const queue = 'my-appengine-queue';
  // const location = 'us-central1';
  // const payload = 'hello';

  // Construct the fully qualified queue name.
  const parent = client.queuePath(project, location, queue);

  const task = {
    appEngineHttpRequest: {
      httpMethod: 'POST',
      relativeUri: '/log_payload',
    },
  };

  if (payload) {
    task.appEngineHttpRequest.body = Buffer.from(payload).toString('base64');
  }

  if (inSeconds) {
    task.scheduleTime = {
      seconds: inSeconds + Date.now() / 1000,
    };
  }

  const request = {
    parent: parent,
    task: task,
  };

  console.log('Sending task:');
  console.log(task);
  // Send create task request.
  const [response] = await client.createTask(request);
  const name = response.name;
  console.log(`Created task ${name}`);
Related