【问题标题】:Cloud Datastore - Error: 14 UNAVAILABLE: Getting metadata from plugin failed with errorCloud Datastore - 错误:14 不可用:从插件获取元数据失败并出现错误
【发布时间】:2018-09-27 08:19:09
【问题描述】:

通过 nodejs sdk 将数据保存到云数据存储时出现以下错误

 Error: 14 UNAVAILABLE: Getting metadata from plugin failed with error: Could not refresh access token.
 at Object.exports.createStatusError
     (/user_code/node_modules/@google-cloud/datastore/node_modules/grpc/src/common.js:87:15)
 at Object.onReceiveStatus
     (/user_code/node_modules/@google-cloud/datastore/node_modules/grpc/src/client_interceptors.js:1188:28)
 at InterceptingListener._callNext
     (/user_code/node_modules/@google-cloud/datastore/node_modules/grpc/src/client_interceptors.js:564:42)
 at InterceptingListener.onReceiveStatus
     (/user_code/node_modules/@google-cloud/datastore/node_modules/grpc/src/client_interceptors.js:614:8)
 at callback
     (/user_code/node_modules/@google-cloud/datastore/node_modules/grpc/src/client_interceptors.js:841:24)
 code: 14, metadata: Metadata { _internal_repr: {} },
     details: 'Getting metadata from plugin failed with error: Could not refresh access token.' 

这里是代码:

// Imports the Google Cloud client library
const Datastore = require('@google-cloud/datastore');

// Your Google Cloud Platform project ID
const projectId = 'YOUR_PROJECT_ID';

// Creates a client
const datastore = new Datastore({
  projectId: projectId,
});

// The kind for the new entity
const kind = 'Task';
// The name/ID for the new entity
const name = 'sampletask1';
// The Cloud Datastore key for the new entity
const taskKey = datastore.key([kind, name]);

// Prepares the new entity
const task = {
  key: taskKey,
  data: {
    description: 'Buy milk',
  },
};

// Saves the entity
datastore
  .save(task)
  .then(() => {
    console.log(`Saved ${task.key.name}: ${task.data.description}`);
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

以下版本

"@google-cloud/datastore": "1.4.1",

【问题讨论】:

  • 我们可以假设'YOUR_PROJECT_ID' 只是实际项目名称的占位符吗?
  • 是的,我从示例代码中复制了代码,并修改为具有项目 ID。
  • 您是否为 Cloud Functions 运行时服务帐户提供了足够的数据存储访问权限? cloud.google.com/functions/docs/concepts/…
  • 是的,这就是问题所在。默认情况下,我实际上必须重新启用服务才能在服务帐户中获取此角色。 cloud.google.com/functions/docs/concepts/… 。文档中也有错误,角色实际上是 cloudfunctions.serviceAgent 并且区分大小写。
  • @SoulMan 您能否发布您对该问题的解决方案,作为对社区有益的答案?

标签: node.js google-cloud-datastore google-cloud-functions


【解决方案1】:

这发生在特定的 GCO 项目中,这些项目是旧的,并且云功能 API 在 GA 发布后从未重置。

根据文档 [1],云功能需要以下角色才能与数据存储区通信。

Cloud Functions 服务帐户 (service-PROJECT_NUMBER@gcf-admin-robot.iam.gserviceaccount.com) 在您的项目中具有 cloudfunctions.serviceAgent 角色。

您可以通过重新启用来将此服务帐户重置为默认角色 云函数 API:

gcloud services enable cloudfunctions.googleapis.com

[1]https://cloud.google.com/functions/docs/concepts/iam#troubleshooting_permission_errors

【讨论】:

    猜你喜欢
    • 2019-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-14
    • 2019-11-23
    • 2019-02-10
    • 2016-03-12
    相关资源
    最近更新 更多