【发布时间】:2019-09-23 16:23:34
【问题描述】:
我正在开发一个 Firebase 云函数,它从存储在 Firebase 存储中的文件中收集元数据
我的代码差不多是这样的:
const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
exports.someFunction = functions.https.onCall((data, context) => {
getMetadata("myBucket", data.filename)
.then(() => {
console.log("OK");
return;
})
.catch(err => {
console.error(err);
})
// do some other stuff here ....
return;
}
async function getMetadata(bucketName, filename) {
const [metadata] = await storage
.bucket(bucketName)
.file(filename)
.getMetadata(); <<== ERROR HAPPENS IN THIS CALL
console.log(metadata.selfLink);
console.log(metadata.size);
}
每当调用storage.bucket(bucketName).file(filename).getMetadata() 时,如上面的代码所示,它会导致 403 并显示“要计费的项目与缺少的计费帐户相关联”。我已经尝试在本地运行它(使用firebase functions:shell)并部署它。以下是完整的错误信息:
{ Error: The project to be billed is associated with an absent billing account.
at Util.parseHttpRespBody (/srv/node_modules/@google-cloud/common/build/src/util.js:191:38)
at Util.handleResp (/srv/node_modules/@google-cloud/common/build/src/util.js:135:117)
at retryRequest (/srv/node_modules/@google-cloud/common/build/src/util.js:423:22)
at onResponse (/srv/node_modules/retry-request/index.js:200:7)
at /srv/node_modules/teeny-request/build/src/index.js:222:13
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
code: 403,
errors:
[ { domain: 'global',
reason: 'accountDisabled',
message: 'The project to be billed is associated with an absent billing account.',
locationType: 'header',
location: 'Authorization' } ],
response: undefined,
message: 'The project to be billed is associated with an absent billing account.' }
该 Firebase 项目已经使用“Blaze 计划”几个星期了,并且结算帐户已经启用了大约一年,还为其他 GCP 项目收费。
我已阅读服务帐户应该具有“signBlob”权限,我尝试通过将“服务帐户令牌创建者”添加到默认 AppEngine 服务帐户和 Firebsae 服务帐户。
我也尝试过通过 Firebase 的管理 SDK 初始化存储
const serviceAccount = require("path-to-json-downloaded-from-firebase-console.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://<my-project>.firebaseio.com"
});
const storage = admin.storage();
但两者都没有运气。
我不知道哪个帐户被“禁用”或“不存在”,也不知道我应该配置什么来让它运行并卡住。
任何可以让我进一步排除故障的指针都会有很大帮助。
【问题讨论】:
标签: node.js google-cloud-functions firebase-storage