根据https://cloud.google.com/docs/authentication/production的说法,在云运行环境中,默认情况下,如果未设置GOOGLE_APPLICATION_CREDENTIALS环境变量,则使用默认的计算服务帐户。
我刚刚部署了一个基本的节点容器镜像,它使用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) {因此,由于某些原因,似乎没有使用默认的服务帐户。有人知道我可能会错过什么吗?
发布于 2020-03-29 03:21:00
结果,我在构建中包含了.env文件。该文件包含环境变量GOOGLE_APPLICATION_CREDENTIALS。从docker版本中排除该文件修复了该问题。
https://stackoverflow.com/questions/60904804
复制相似问题