部署无服务器 GCP 时如何解决错误:“部署失败:RESOURCE_ERROR”(不推荐使用 GCF v1beta2 API)?

MTZ*_*TZ4 2 deployment google-cloud-platform serverless-framework

不知道为什么,但是无服务器 GCP 的成功部署停止了错误:

team27> serverless deploy -c serverless_stage.yml
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Compiling function "user"...
Serverless: Compiling function "volunteer"...
Serverless: Compiling function "clear"...
Serverless: Uploading artifacts...
Serverless: Artifacts successfully uploaded...
Serverless: Updating deployment...
Serverless: Checking deployment update progress...
..
  Error --------------------------------------------------

  Error: Deployment failed: RESOURCE_ERROR

       {"ResourceType":"cloudfunctions.v1beta2.function","ResourceErrorCode":"403","ResourceErrorMessage":{"code":403,"message":"The GCF v1beta2 API is deprecated. See https://cloud.google.com/functions/docs/migrating","status":"PERMISSION_DENIED","details":[],"statusMessage":"Forbidden","requestPath":"https://cloudfunctions.googleapis.com/v1beta2/projects/stageteam27/locations/us-central1/functions","httpMethod":"POST"}}
      at throwErrorIfDeploymentFails (xxx\team27\node_modules\serverless-google-cloudfunctions\shared\monitorDeployment.js:71:11)
      at xxx\team27\node_modules\serverless-google-cloudfunctions\shared\monitorDeployment.js:42:17
      at processTicksAndRejections (internal/process/task_queues.js:93:5)

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          win32
     Node Version:              12.13.1
     Framework Version:         1.64.0
     Plugin Version:            3.4.0
     SDK Version:               2.3.0
     Components Core Version:   1.1.2
     Components CLI Version:    1.4.0
Run Code Online (Sandbox Code Playgroud)

正如https://cloud.google.com/functions/docs/migrating 中所建议的, 我执行了gcloud components update 相同的错误...

这是我的 yml:

service: stageteam27

provider:
  name: google
  stage: stage
  runtime: nodejs10
  region: us-central1
  project: stageteam27
  credentials: /xxx/stageteam27keyfile.json
  environment:
    IS_PROD: 'false'

plugins:
  - serverless-google-cloudfunctions

package:
  exclude:
    - node_modules/**
    - .gitignore
    - .git/**

functions:
  user:
    handler: userMessage
    events:
      - http: user

  volunteer:
    handler: volunteerMessage
    events:
      - http: volunteer

  clear:
    handler: clearCommand
    events:
      - http: clear
Run Code Online (Sandbox Code Playgroud)

Apr*_*ndi 6

如果您使用无服务器框架在 GCP 中部署云功能,以下参考可能对您有所帮助,

https://github.com/serverless/serverless-google-cloudfunctions/blob/HEAD/MIGRATION_GUIDE.md


选项 2

第二个是从开发人员的角度来看,这意味着您需要对 serverless.yml 进行一些更改。

1. Change the service name or change the function name to make sure this function is different from the older one.

2. Redeploy the functions.

3. Once it's done?you may consider delete the old ones.
Run Code Online (Sandbox Code Playgroud)

除了将serverless库和serverless-google-cloudfunctions插件升级到最新版本外,您还可以尝试将服务重命名为其他名称stageteam27(例如stageteam27-v2stageteam27-new、 或stage-team-27)。

就我而言,仅重命名函数并不能解决部署问题,而服务名称仍然是旧的。

只需说明一下,函数名称现在将具有以下模式 ${serviceName}-${stage}-${functionName}

编辑

serverless.yml如果我们不想有这么长的函数名,我们可以在 中指定函数名。

例如

service: myService

provider:
  name: google
  stage: prod
  runtime: nodejs10

functions:
  myFunction:
    # this will be the function name
    name: myFunction
    handler: myFunctionHandler
Run Code Online (Sandbox Code Playgroud)

在这种情况下,部署的函数名称将myFunction仅为。如果我们不指定名称,它将是myService-prod-myFunction.