【发布时间】:2020-07-09 07:15:08
【问题描述】:
根据https://cloud.google.com/docs/authentication/production,在Cloud Run环境中,默认情况下,如果没有设置GOOGLE_APPLICATION_CREDENTIALS环境变量,则使用默认的Compute Service账号。
我刚刚部署了一个基本的节点容器镜像,它使用googleapis 库,如下所示:
const { google } = require('googleapis')
const auth = new google.auth.GoogleAuth({
scopes: [],
});
const client = await auth.getClient();
但是,在 Cloud Run 日志中,我可以看到容器无法启动并出现以下错误:
Error: The file at credentials/service_account.json does not exist, or it is not a file. ENOENT: no such file or directory, lstat '/app/credentials' at Object.realpathSync (fs.js:1546:7) at GoogleAuth._getApplicationCredentialsFromFilePath (/app/node_modules/google-auth-library/build/src/auth/googleauth.js:250:27) at GoogleAuth._tryGetApplicationCredentialsFromEnvironmentVariable (/app/node_modules/google-auth-library/build/src/auth/googleauth.js:192:25) at GoogleAuth.getApplicationDefaultAsync (/app/node_modules/google-auth-library/build/src/auth/googleauth.js:130:33) at GoogleAuth.getClient (/app/node_modules/google-auth-library/build/src/auth/googleauth.js:502:28) at Object.authorize (/app/api.js:18:29) at Object.<anonymous> (/app/index.js:547:4) at Module._compile (internal/modules/cjs/loader.js:1158:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10) at Module.load (internal/modules/cjs/loader.js:1002:32) {
因此,出于某种原因,似乎没有使用默认服务帐户。有谁知道我在这里可能缺少什么?
【问题讨论】:
-
您的代码中的某些内容正在设置
credentials/service_account.json。您只发布部分代码,没有部署文件。 -
@JohnHanley 你是对的。我搜索了源代码,并没有找到它。原来我将它设置在
.env文件中。感谢您的建议。
标签: node.js google-cloud-platform google-api-nodejs-client google-cloud-run