我想更新 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
但它只能是字符串而不是 bool 值
。
最佳答案
文档 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")
}
关于node.js - AWS Lambda 的环境变量可以设置为 bool 值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65279870/