如何解决部署无服务器 GCP 时出现错误:"Deployment failed: RESOURCE_ERROR"(GCF v1beta2 API 已弃用)?



不确定原因,但无服务器 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 (xxxteam27node_modulesserverless-google-cloudfunctionssharedmonitorDeployment.js:71:11)
at xxxteam27node_modulesserverless-google-cloudfunctionssharedmonitorDeployment.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

如 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

如果您使用无服务器框架在 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.

除了将serverless库和serverless-google-cloudfunctions插件升级到最新版本外,您还可以尝试将服务重命名为stageteam27以外的其他名称(例如stageteam27-v2stageteam27-newstage-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

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

Google实际上弃用了他们以前版本的Cloud Functions API。不久前,对Google Cloud Functions提供商进行了更改,您可能还没有,因此请尝试使用npm i -g serverless升级框架,它应该可以解决问题。如果做不到这一点,请尝试查看您使用的serverless-google-cloudfunctions模块版本并对其进行升级。

通过 serverless.com 模板安装时,package.json引用"serverless-google-cloudfunctions": "^2.3.3"。版本 2.x 是问题所在。使用版本 3.x 重新安装软件包。

我在package.json中删除了那行并运行了npm install serverless-google-cloudfunctions.

这个安装的反面^3.1.1和我的serverless deploy工作了。

"dependencies": { "serverless-google-cloudfunctions": "^2.3.3"} package.json 更改版本 '^3.0.0'

最新更新