简体   繁体   English

Firebase 函数:无法加载默认凭据

[英]Firebase Functions: Could not load default credentials

I have a Firebase Function that subscribes to a Cloud PubSub topic.我有一个订阅 Cloud PubSub 主题的 Firebase 函数。 App is initialized very simply like this:应用程序的初始化非常简单,如下所示:

import * as admin from 'firebase-admin';

admin.initializeApp();

I'm getting this error:我收到此错误:

"Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information. at GoogleAuth.getApplicationDefaultAsync (/srv/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:161:19) at process._tickCallback (internal/process/next_tick.js:68:7)" “错误:无法加载默认凭据。浏览到https://cloud.google.com/docs/authentication/getting-started了解更多信息。在 GoogleAuth.getApplicationDefaultAsync (/srv/functions/node_modules/google-auth-library /build/src/auth/googleauth.js:161:19) 在 process._tickCallback (internal/process/next_tick.js:68:7)"

Here's the weird thing.这是奇怪的事情。 It typically works.它通常有效。 In other words, if I trigger it a second time it works.换句话说,如果我第二次触发它,它就会起作用。 And a third time.第三次。 Most often it seems to fail the first time it runs after a new firebase deploy and possibly on a "cold start."大多数情况下,它似乎在新的firebase deploy之后第一次运行时失败,并且可能在“冷启动”时失败。

Not sure what I'm doing wrong and why it would fail only on the first run.不确定我做错了什么以及为什么它只会在第一次运行时失败。

SOLVED!解决了! This answer helped: Error: Could not load the default credentials (Firebase function to firestore)这个答案有帮助: 错误:无法加载默认凭据(Firebase 函数到 firestore)

From within a Firebase Function for an API call, I was publishing to a Cloud PubSub topic like this:在用于 API 调用的 Firebase 函数中,我发布到一个 Cloud PubSub 主题,如下所示:

pubsub.topic(topicName).publish(dataBuffer, customAttributes)

I was not awaiting the response and was immediately sending the 2XX HTTP response back to the client.我没有等待响应,而是立即将 2XX HTTP 响应发送回客户端。 The execution seemed to continue fine, but obviously it did not behave as intended.执行似乎继续正常,但显然它没有按预期运行。

Sometimes the API response call itself would fail (and never publish the message), but sometimes not.有时API 响应调用本身会失败(并且永远不会发布消息),但有时不会。 In other cases, the publish would succeed but the Firebase Function subscribing to the topic would fail!在其他情况下,发布会成功,但订阅主题的 Firebase 函数会失败!

In all cases, this seemed to resolve itself after running the script a second time.在所有情况下,这似乎在第二次运行脚本后自行解决。 For this reason, I still believe it had something to do with a cold start.因此,我仍然认为这与冷启动有关。

But since I changed it to await like this:但是因为我把它改成这样等待:

await pubsub.topic(topicName).publish(dataBuffer, customAttributes)

I have not seen this problem happen again.我还没有看到这个问题再次发生。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase 函数访问 Firestore 错误:无法加载默认凭据 - Firebase Functions Accessing Firestore error: Could not load the default credentials Firebase 云函数:获取应用程序默认凭据时出现意外错误。 无法加载默认凭据 - Firebase cloud functions: Unexpected error while acquiring application default credentials. Could not load the default credentials 错误:无法加载默认凭据(Firebase function 到 firestore) - Error: Could not load the default credentials (Firebase function to firestore) 错误:无法加载默认凭据。 - 云功能 - Error: Could not load the default credentials. - Cloud Functions 错误:无法加载默认凭据。 上下文:firebase 登录:ci 和 firebase 身份验证:导出 - Error: Could not load the default credentials. context: firebase login:ci AND firebase auth:export TwiML 应用程序和 Firebase 抛出未处理的承诺拒绝:错误:无法加载默认凭据 - TwiML app and Firebase throwing Unhandled promise rejection: Error: Could not load the default credentials admin.auth().verifyIdToken(idToken) 错误:在 8.0.0 之后无法使用 firebase-admin 加载默认凭据 - admin.auth().verifyIdToken(idToken) Error: Could not load the default credentials whith firebase-admin after to 8.0.0 Ruby的Firestore-无法加载默认凭据 - Firestore from Ruby - Could not load the default credentials 错误:无法加载默认凭据 — 凭据很好,function 死了 - Error: could not load the default credentials — creds are fine, function dies 为什么最新的 Firebase 服务不能再加载默认凭据 - Why can't latest firebase serve load the default credentials anymore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM