INVALID_ARGUMENT: Location 'europe-west1' is not a valid location

Viewed 343

My error code after calling the below (which is shortened for brevity) within a cloud functions is:

Error: 3 INVALID_ARGUMENT: Location 'europe-west1' is not a valid location. Use ListLocations to list valid locations.

If I change to location to "us-central" for example, the error code changes to:

Error: 3 INVALID_ARGUMENT: Location must equal europe-west1 because the App Engine app that is associated with this project is located in europe-west1

I have had a look on stackoverflow for similar but came up short. I left a comment on this question to see if the op had any luck:

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

Where am I going wrong?

Thanks!

JT

OS: Google Cloud Functions Node.js version: 12 npm version: 6.14.10 @google-cloud/tasks version: 2.3.0

Steps to reproduce

const functions = require('firebase-functions');
const {CloudTasksClient} = require("@google-cloud/tasks");
const admin = require('firebase-admin');

const client = new CloudTasksClient({ fallback: true });

// Omit the actual triggered function

async function createHttpTasks(session) {
  const project = "XXXXX"; // These match my project and queue id/name
  const queue = "XXXXXX";
  const location = "europe-west1";
  
  // Construct the fully qualified queue name.
  const parent = client.queuePath(project, location, queue);
  
  // Do stuff
  
  const requestCheck = {parent, taskCheckIn};
  await client.createTask(requestCheck);
}
2 Answers

I had two things wrong:

const client = new CloudTasksClient({ fallback: true });

should have been:

const client = new CloudTasksClient();

and

const requestCheck = {parent, taskCheckIn};

should have been

const requestCheck = {parent, task: taskCheckIn};

thanks to the gcloud team for responding to my issue:

https://github.com/googleapis/nodejs-tasks/issues/509

If anyone else is getting this error, make sure there are no spaces in the location variable. For example, there is a space at the end of the variable:

location="europe-west-3 "

Related