node.js - 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 实例吗?
解决方案
我按原样复制了您的代码,但出现了错误:
错误:字段“区域”的值无效:“us-central1”。未知区域
例如,我更新了您的代码以使用“us-central1-c”区域,它成功创建了 VM。
推荐阅读
- mysql - 在 Django 中用 MySQL 数据库替换 SQLite 数据库
- mongodb - 有没有人能够在 cosmos mongodb 上使用带有日期字段的 ttl?
- python - 如何使用 replit 在 pygame 中显示字体
- cuda - CUDA 异步内存复制 - 哪个硬件设备执行内存复制操作?
- node.js - Heroku /bin/sh: 1: g++: 未找到
- java - bluetoothAdapter.startDiscovery() 没有返回任何内容,或者 Android 中未调用 BroadcastReceiver 接收器
- excel - Excel Cube 函数 Power Pivot 模型
- python - urllib.request.urlopen 对某些 URL 成功,对其他 URL 超时
- reactjs - php 会话随每个请求而变化
- javascript - 这里需要 eval 函数吗?