首页 > 解决方案 > Google Cloud Functions 中出现“错误:无法刷新访问令牌”

问题描述

我要做的是执行用Node.js编写的云函数并在GCE中创建vm实例。

我已经实现了在 GCE 中创建 vm 实例的云功能。我多次尝试执行云功能,但没有创建虚拟机实例。

云函数运行时:Node.js 8

源代码如下所示。index.js

const Compute = require('@google-cloud/compute');
const compute = new Compute();
exports.startInstance = function startInstance(req, res) {
    const zone = compute.zone('us-central1-c');
    zone.createVM("test", {os: 'ubuntu'});
    console.log('instance start successfully');
res.status(200).send('Success start instance');
};

包.json

{
  "name": "startInstance",
  "version": "1.0.0",
  "description": "create gce instance",
  "main": "index.js",
  "dependencies": {
    "@google-cloud/compute": "1.0.0"
  }
}

有时会出现以下错误。


"textPayload": "Error: Could not refresh access token: Unsuccessful response status code. Request failed with status code 500\n    at Gaxios.request (/srv/node_modules/gaxios/build/src/gaxios.js:70:23)\n    at <anonymous>\n    at process._tickDomainCallback (internal/process/next_tick.js:229:7)",
  "insertId": "000000-58d51a97-122c-4531-9c9a-00b19695e93d",
  "resource": {
    "type": "cloud_function",
    "labels": {
      "project_id": "$project_id",
      "region": "asia-northeast1",
      "function_name": "function-2"
    }
  },
  "timestamp": "2019-07-25T12:44:02.802Z",
  "severity": "ERROR",
  "labels": {
    "execution_id": "jjcat6rtw49n"
  },
  "logName": "projects/$project_id/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
  "trace": "projects/$project_id/traces/be422ca287727cdf58d8275925c176ab",
  "receiveTimestamp": "2019-07-25T12:44:08.781094017Z"
}

你能告诉我为什么没有创建 GCE 中的 vm 实例吗?

标签: node.jsgoogle-cloud-platformgoogle-cloud-functions

解决方案


我按原样复制了您的代码,但出现了错误:

错误:字段“区域”的值无效:“us-central1”。未知区域

例如,我更新了您的代码以使用“us-central1-c”区域,它成功创建了 VM。


推荐阅读