Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a dev and prod instance of the same cloud function using serverless?

I have a Cloud Function named getVendors that is deployed using serverless. I need to create both a dev and production instance of the same function. When I deploy using the dev variable in my yml file, it overwrites the function currently in GCP.

How do I deploy a dev instance of the same cloud function without overwriting the production instance?

For reference, I have two stacks (dev and prod) visible in the Deployment Manager. It's when I look at Cloud Functions in the project, there is only one function listed in the project. This is the function that gets overwritten.

service: get-vendor-info

provider:
  name: google
  stage: production
  runtime: nodejs8
  region: us-central1
  project: {PROJECT NAME IS HIDDEN}
  # the path to the credentials file needs to be absolute
  credentials:{MY_CREDENTIALS}.json

plugins:
  - serverless-google-cloudfunctions

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

functions:
  getVendors:
    handler: getVendors
    events:
      - event: 
          eventType: providers/cloud.pubsub/eventTypes/topic.publish
          resource: projects/{MY_PROJECT_NAME}/topics/getVendors

like image 497
Kim Merino Avatar asked Jan 16 '26 23:01

Kim Merino


1 Answers

I use two different GCP projects; one for dev/test and another for prod. If there are multiple developers on the team you should consider giving each of them their own dev project as well.

By doing that you reduce the risk of development or testing work messing up production data. You could copy the production database into the dev/test project nightly, and potentially add special test data to it as well. This special test data could be corner cases, well-known data to run automated tests against, etc.

For a more in-depth discussion, check out this talk from Google Cloud Next: https://youtu.be/41QvqGfbz9o?t=1142

like image 117
Martin Omander Avatar answered Jan 19 '26 19:01

Martin Omander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!