You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为Google Cloud Run配置VPC访问时遇参数错误求助

问题:Cloud Run部署带私有VPC连接器的服务时参数错误

部署时持续报错:

Error: 3 INVALID_ARGUMENT: Violation in CreateServiceRequest.service.template.vpc_access.connector: one and only one of connector and network_interfaces must be set.

移除VPC配置后脚本可正常部署,相关代码如下:

const parent = 'projects/***/locations/us-central1';

const service = {
      template: {
          vpcAccess: [
              {
                  connector: 'projects/***/locations/us-central1/connectors/socket-connector-name',
                  egress: 'private-ranges-only'
              }
          ],
          containers: [
              {
                  image: '***',
              },
          ]
      },
  };

const serviceId = 'abc123';

const { ServicesClient } = require('@google-cloud/run').v2;
const runClient = new ServicesClient();

async function callCreateService() {
  const request = {
    parent,
    service,
    serviceId,
  };

  const [operation] = await runClient.createService(request);
  const [response] = await operation.promise();
  console.log(response);
}

callCreateService();
解决方案

问题出在vpcAccess的定义上——你把它写成了数组,但Cloud Run v2 API要求vpcAccess是一个单个对象,而非数组。API会将数组格式的vpcAccess识别为多组配置,触发"只能设置connector或network_interfaces其中一项"的校验规则。

修正后的service对象如下:

const service = {
      template: {
          vpcAccess: {
              connector: 'projects/***/locations/us-central1/connectors/socket-connector-name',
              egress: 'private-ranges-only'
          },
          containers: [
              {
                  image: '***',
              },
          ]
      },
  };

只需移除vpcAccess外层的[],改为普通对象格式即可正常部署。

内容的提问来源于stack exchange,提问作者Thomas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 10:35:58