Google Cloud Tasks:位置"europe-west1"不是有效的位置 [英] Google Cloud Tasks: Location 'europe-west1' is not a valid location

查看:69
本文介绍了Google Cloud Tasks:位置"europe-west1"不是有效的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Cloud Function运行Google Cloud Tasks任务,但是我遇到错误,因为我尝试使用的任何区域都不正确.

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:

错误:{代码":3,消息":位置' europe-west1'不是有效位置.请使用ListLocations列出有效位置.",详细信息":[]}

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

例如,如果我尝试使用us-central1,它将报告:

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

错误:{代码":3,消息":"位置必须等于europe-west1,因为与此项目相关联的App Engine应用程序位于europe-west1 ","详细信息":[]}

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":[]}

我将Google Cloud Tasks API与Node.js结合使用来创建新任务:

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);

可以在此处找到完整的示例: https://github.com/googleapis/nodejs-tasks/blob/master/samples/createHttpTaskWithToken.js

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

所调用的URL是:" https://cloudtasks.googleapis.com:443/ $ rpc/google.cloud.task.v2beta3.CloudTasks/CreateTask"

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

如果我运行locations list命令,则输出为:

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

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

使用REST API( https://cloud.google.com/tasks/docs/reference/rest/v2beta3/projects.locations.queues.tasks/create ).可能是客户端中的错误?

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.

推荐答案

我意识到您正在使用的示例适用于非App Engine/Cloud函数环境,请尝试使用

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.

请检查您的package.json是否定义了最新版本的google-cloud/tasks库,目前为1.9.0

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

您无需在App Engine/Cloud Functions环境中使用Ouath令牌,因为已经使用服务帐户进行了配置.

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}`);

这篇关于Google Cloud Tasks:位置"europe-west1"不是有效的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆