AWS Lambda 的环境变量可以设置为布尔值吗?
Can AWS Lambda's environment variable be set to a boolean value?
我想更新 Lambda 函数的环境变量,这是我当前使用的代码。
const AWS = require("aws-sdk");
exports.handler = async (event, context) => {
const res = await updateConfig("test");
};
async function updateConfig(funcName) {
const lambda = new AWS.Lambda({
region: "us-east-2"
});
const params = {
FunctionName: funcName,
Environment: {
Variables: {
"debug": true
}
}
};
const data = await lambda.updateFunctionConfiguration(params).promise();
return data;
}
目前此代码不起作用,因为我正在尝试将环境变量 debug
设置为 true
,但它只能是字符串,而不是 boolean
。
文档https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html
将键值对引用为:
An environment variable is a pair of strings that are stored in a function's version-specific configuration.
您可以使用:
Environment: {
Variables: {
"debug": "true"
}
}
并在您的函数中相应地检查变量:
if(process.env.debug === "true") {
console.log("debug is set to true")
}
我想更新 Lambda 函数的环境变量,这是我当前使用的代码。
const AWS = require("aws-sdk");
exports.handler = async (event, context) => {
const res = await updateConfig("test");
};
async function updateConfig(funcName) {
const lambda = new AWS.Lambda({
region: "us-east-2"
});
const params = {
FunctionName: funcName,
Environment: {
Variables: {
"debug": true
}
}
};
const data = await lambda.updateFunctionConfiguration(params).promise();
return data;
}
目前此代码不起作用,因为我正在尝试将环境变量 debug
设置为 true
,但它只能是字符串,而不是 boolean
。
文档https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html 将键值对引用为:
An environment variable is a pair of strings that are stored in a function's version-specific configuration.
您可以使用:
Environment: {
Variables: {
"debug": "true"
}
}
并在您的函数中相应地检查变量:
if(process.env.debug === "true") {
console.log("debug is set to true")
}