【发布时间】:2020-07-31 14:18:55
【问题描述】:
喂! 你好吗?
我正在开发Google Cloud Function,它很棒! 但自上周以来,我在本地使用 functions-framework-nodejs 进行测试时遇到问题
Unhandled rejection
Error: 7 PERMISSION_DENIED: The caller does not have permission
at Object.callErrorFromStatus (/home/user/project/node_modules/@grpc/grpc-js/build/src/call.js:31:26)
at Object.onReceiveStatus (/home/user/project/node_modules/@grpc/grpc-js/build/src/client.js:176:52)
at Object.onReceiveStatus (/home/user/project/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:342:141)
at Object.onReceiveStatus (/home/user/project/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:305:181)
at Http2CallStream.outputStatus (/home/user/project/node_modules/@grpc/grpc-js/build/src/call-stream.js:117:74)
at Http2CallStream.maybeOutputStatus (/home/user/project/node_modules/@grpc/grpc-js/build/src/call-stream.js:156:22)
at Http2CallStream.endCall (/home/user/project/node_modules/@grpc/grpc-js/build/src/call-stream.js:142:18)
at Http2CallStream.handleTrailers (/home/user/project/node_modules/@grpc/grpc-js/build/src/call-stream.js:274:14)
at ClientHttp2Stream.emit (events.js:198:13)
at ClientHttp2Stream.EventEmitter.emit (domain.js:466:23)
Error: Process exited with code 16
at process.on.code (/home/user/project/node_modules/@google-cloud/functions-framework/build/src/invoker.js:271:38)
at process.emit (events.js:198:13)
at process.EventEmitter.emit (domain.js:448:20)
at process.exit (internal/process/per_thread.js:168:15)
at Object.logAndSendError (/home/user/project/node_modules/@google-cloud/functions-framework/build/src/logger.js:37:9)
at process.on.err (/home/user/project/node_modules/@google-cloud/functions-framework/build/src/invoker.js:268:22)
at process.emit (events.js:198:13)
at process.EventEmitter.emit (domain.js:448:20)
at emitPromiseRejectionWarnings (internal/process/promises.js:140:18)
at process._tickCallback (internal/process/next_tick.js:69:34)
error Command failed with exit code 16.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
在函数执行结束时发生。
有什么线索吗?
谢谢!
更新:
在 José Soni 向我询问代码后,试图隔离代码的某些部分,它似乎是 LogginWinston 导致错误,当我在创建记录器时评论“loggingWinston”时,它工作得很好.我检查了日志 API 权限,看起来不错。代码如下!
/** libraries */
const winston = require('winston')
const { LoggingWinston } = require('@google-cloud/logging-winston')
const loggingWinston = new LoggingWinston()
// Create a Winston logger that streams to Stackdriver Logging
// Logs will be written to: "projects/YOUR_PROJECT_ID/logs/winston_log"
const logger = winston.createLogger({
level: 'info',
transports: [
new winston.transports.Console({
level: 'debug',
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple()
)
}),
// Add Stackdriver Logging
loggingWinston
]
})
exports.execute = async (_request, response) => {
logger.info('START')
response.status(200).end()
}
【问题讨论】:
-
能否分享一下云函数的代码,以及执行它的用户,这是为了知道为什么会触发权限被拒绝。
-
嗨@JoséSoní 我已经用代码更新了帖子,用户是指本地用户还是 GCP 用户?本地用户是我的默认 linux 用户,在 GCP 中我是项目的所有者。谢谢!
-
我指的是GCP账号中的用户,哪个服务账号关联了云功能?是默认的吗?
-
是的,它是默认用户!
-
是执行部署的云功能还是本地测试时出现的错误?
标签: node.js google-cloud-platform google-cloud-functions serverless