MTZ4
MTZ4

Reputation: 2346

How to solve Error: "Deployment failed: RESOURCE_ERROR" (The GCF v1beta2 API is deprecated) when deploying serverless GCP?

not sure why but succesfull deployments for serverless GCP stopped working with the error:

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

As suggested in https://cloud.google.com/functions/docs/migrating I performed gcloud components update Same error...

Here is my 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

Upvotes: 3

Views: 1484

Answers (4)

Puujee.Ts
Puujee.Ts

Reputation: 91

"dependencies": { "serverless-google-cloudfunctions": "^2.3.3" } package.json change version '^3.0.0'

Upvotes: 0

Coder1
Coder1

Reputation: 13321

When installing via serverless.com templates, package.json referenced "serverless-google-cloudfunctions": "^2.3.3". Version 2.x is the problem. Reinstall the package with version 3.x.

I deleted that line in package.json and ran npm install serverless-google-cloudfunctions.

This installed versoin ^3.1.1 and my serverless deploy worked.

Upvotes: 1

Aprian Diaz Novandi
Aprian Diaz Novandi

Reputation: 419

If you are using serverless framework to deploy your cloud functions in GCP, this following reference might help you,

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


Option 2

The second is from the developers' point of view, which means that you need to make some changes to the 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.

In addition to upgrading the serverless library and serverless-google-cloudfunctions plugin to the latest version, you can try to rename the service to other name than stageteam27 (e.g. stageteam27-v2, stageteam27-new, or stage-team-27).

In my case, only renaming the function cannot solve the deployment issue while the service name is still the old one.

Just one remark that the function name will now have the following pattern ${serviceName}-${stage}-${functionName}.

EDIT:

We can specify function name in the serverless.yml if we do not want to have such long function name.

For instance

service: myService

provider:
  name: google
  stage: prod
  runtime: nodejs10

functions:
  myFunction:
    # this will be the function name
    name: myFunction
    handler: myFunctionHandler

In that case, the deployed function name will be myFunction only. If we do not specify the name, it will be myService-prod-myFunction.

Upvotes: 6

Gareth McCumskey
Gareth McCumskey

Reputation: 1540

Google actually deprecated their previous version of the Cloud Functions API. There were changes made not so long to the Google Cloud Functions provider that you may nbot yet have so try upgrading the framework using npm i -g serverless and it should fix the issue. Failing that, try to see which version of the serverless-google-cloudfunctions module you use and upgrade that.

Upvotes: 2

Related Questions