1
votes

How do I deploy a Google Cloud function with Serverless framework if I need to specify a connector see https://cloud.google.com/functions/docs/connecting-vpc

I've tried adding these lines to serverless.yml:

vpc_access_connector:
  name: rojects/PROJECT_ID/locations/REGION/connectors/CONNECTOR_NAME

Also I tried this:

vpc_connector: rojects/PROJECT_ID/locations/REGION/connectors/CONNECTOR_NAME

As a result connector is not added.

To deploy a function I use serverless deploy command https://serverless.com/framework/docs/providers/google/guide/intro/

2
Post the error message you're getting. I'm not familiar with Serverless framework but I guess rojects/PROJECT_ID/locations/REGION/connectors/CONNECTOR_NAME would never work as a value compared to projects/PROJECT_ID/locations/REGION/connectors/CONNECTOR_NAME. So is that a typo on the post or a mistake that it's causing the issue.fbraga

2 Answers

2
votes

You have not said much about how you create and deploy the function. The link you posted mentions it is possible to edit the VPC Connector field after a function is deployed. So that should be one way. Deploy the function and then edit its settings to specify the VPC Connector to use.

Update

A more configurable solution might be to use a deployment manager template. You can use the one available here as a starting point. But it does not have VPC connector configuration built-in so you will need to update that template to include VPC connector configuration.

1
votes

You can add a VPC connector by adding vpc property to a function in serverless.yml. No idea why it is not in the documentation.

functions:
  first:
    handler: yourHandler
    events:
      - http: path
    vpc: projects/{project_id}/locations/{region}/connectors/{connector_name}