【发布时间】:2020-03-01 15:26:31
【问题描述】:
我在 2 个不同的 GCP 项目(暂存和生产)中运行相同的云函数。
在暂存项目中,Cloud Functions 运行良好,但在生产中它会引发以下异常:
Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
at GoogleAuth.getApplicationDefaultAsync (/srv/node_modules/@google-cloud/common/node_modules/google-auth-library/build/src/auth/googleauth.js:161:19)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)"
在生产中导致问题的部分是:
function saveContentToBucket(contents, destination, bucket, gzip){
const bucket = storage.bucket(FIRESTORE_BUCKET_NAME);
const file = bucket.file(destination);
file.save(JSON.stringify(contents), function(err) {
if(err) console.log("saveContentToBucket | err:", err)
});
}
这是我启动项目和存储的方式。
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
// Firebase related stuff
const functions = require('firebase-functions');
admin.initializeApp(functions.config().firebase);
由于我将相同的功能部署到两个项目,我不明白为什么它在生产中出现问题,而不是暂存。
通常是什么导致默认凭据出现问题? 我跟踪了跟踪中的链接,但它与实际问题无关。
谢谢。
【问题讨论】:
-
几乎肯定不相关,但
FIRESTORE_BUCKET_NAME是如何定义的? -
它是一个变量,在 staging env 中工作。我相信我使用@Doug 回答解决了它。
标签: firebase google-cloud-platform google-cloud-storage firebase-storage