functions-framework-nodejs PERMISSION_DENIED:调用者没有权限

时间:2020-07-31 14:18:55

标签: node.js google-cloud-platform google-cloud-functions serverless

嗨! 你好吗?

我正在开发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()
}

1 个答案:

答案 0 :(得分:1)

我认为我发现了问题,这不是真正的问题,但似乎在@ google-cloud / logging-winston中。

该服务帐户缺少Logging API的权限。 我认为只是消息并不清楚。

但是代码就在这里:

https://github.com/denisdnc/cloud-functions-example

设置服务帐户凭据路径:

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/credential.json"

并启动应用程序:

npx @google-cloud/functions-framework --target=execute

在http:// localhost:8080 /

上执行请求

然后应该在上面记录问题。

谢谢你们的支持!