2 amazon-web-services node.js aws-lambda aws-sdk-nodejs
我想更新 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;
}
Run Code Online (Sandbox Code Playgroud)
目前此代码不起作用,因为我试图将环境变量设置debug为true,但它只能是字符串而不是boolean.
文档https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html 将键和值对引用为:
环境变量是存储在函数的版本特定配置中的一对字符串。
您可以使用:
Environment: {
Variables: {
"debug": "true"
}
}
Run Code Online (Sandbox Code Playgroud)
并在函数中相应地检查变量:
if(process.env.debug === "true") {
console.log("debug is set to true")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5798 次 |
| 最近记录: |