firebase云函数配置参数如何使用动态值:vpcConnector

xqkwcwgp  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(119)

我想创建下面的firebase云函数:

import * as functions from "firebase-functions";

export const myCloudFunction = functions
    .runWith({vpcConnector: process.env.VPC_CONNECTOR})
    .region("asia-south1").https.onRequest(app);

但是,当我部署这个函数时,它无法读取环境变量(我已经检查过它在其他地方工作正常)。我得到以下错误:

VPC connector projects/my-project/locations/asia-south1/connectors/undefined is not ready yet or does not exist.

但是,如果我提供一个静态值,即vpcConnector: "my-google-vpc",一切正常!
先谢谢你了。

9lowa7mx

9lowa7mx1#

当firebase工具在部署期间阅读代码时,环境变量似乎不可用[ discussion ]
我不得不使用firebase参数从环境变量中获取VPC_CONNECTOR的值:

const environment = defineString("MODE");
const vpcConnectorVar = defineString("VPC_CONNECTOR");
const vpcConnectorName = environment.equals("PRODUCTION")
    .thenElse(vpcConnectorVar, "");

export const myCloudFunction = functions
    .runWith({vpcConnector: vpcConnectorName})
    .region("asia-south1").https.onRequest(app);

相关问题