Google云功能访问BigQuery



我正在尝试编写一个访问我的bigquery数据的Google云功能。但是,运行时会出现错误。如果我在本地仿真器下运行,则可以正常工作,但在部署时不行。

我的软件包:

{
  "dependencies": {
    "@google-cloud/bigquery": "^0.9.6"
  }
}

index.js

var BigQuery = require('@google-cloud/bigquery');
exports.hello = function hello(req, res) {
    var bigQuery = BigQuery({ projectId: 'influence-ranking' });
    bigQuery.query({
        query: 'SELECT label from `influence-ranking.wikidata.labels` LIMIT 1',
        useLegacySql: false
    }).then(function () {
        return res.status(200).send('hello');
    }).catch(function (error) {
        return res.status(500).json(error);
    });
};

i部署功能:

$ gcloud beta functions deploy hello --stage-bucket influence-ranking-web --trigger-http --project influence-ranking
Copying file:///tmp/tmpwR3Sza/fun.zip [Content-Type=application/zip]...
/ [1 files][  7.3 KiB/  7.3 KiB]                                                
Operation completed over 1 objects/7.3 KiB.                                      
Deploying function (may take a while - up to 2 minutes)...done.                                                                      
availableMemoryMb: 256
entryPoint: hello
httpsTrigger:
  url: https://us-central1-influence-ranking.cloudfunctions.net/hello
labels:
  deployment-tool: cli-gcloud
latestOperation: operations/aW5mbHVlbmNlLXJhbmtpbmcvdXMtY2VudHJhbDEvaGVsbG8vdHJoV1pjeWlnSkk
name: projects/influence-ranking/locations/us-central1/functions/hello
serviceAccount: tfc7c97f9c5ac6052-tp@appspot.gserviceaccount.com
sourceArchiveUrl: gs://influence-ranking-web/us-central1-hello-poucdhlbhptc.zip
status: READY
timeout: 60s
updateTime: '2017-09-20T18:42:22Z'
versionId: '15'

$ curl https://us-central1-influence-ranking.cloudfunctions.net/hello
{"code":403,"errors":[{"domain":"usageLimits","reason":"accessNotConfigured","message":"Access Not Configured. BigQuery API has not been used in project 283683622993 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/bigquery.googleapis.com/overview?project=283683622993 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.","extendedHelp":"https://console.developers.google.com/apis/api/bigquery.googleapis.com/overview?project=283683622993"}],"message":"Access Not Configured. BigQuery API has not been used in project 283683622993 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/bigquery.googleapis.com/overview?project=283683622993 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry."}

错误消息中的链接给出了错误:

The API "bigquery.googleapis.com" doesn't exist or you don't have permission to access it

看来,项目参数与我在Google Cloud Console中列出的项目编号不符。因此,这让我认为我以某种方式收到了针对错误项目的请求,但我不知道如何。

在我的Google Cloud Functions帐户中弄乱了一些东西。

我结束了:

  1. 删除我所有的功能
  2. 禁用Google云功能
  3. 重新增强Google Cloud功能

现在起作用。

重要的是,部署的输出现在说:

serviceAccount: influence-ranking@appspot.gserviceaccount.com

因此,它使用了正确的服务帐户。

相关内容

  • 没有找到相关文章

最新更新