I want to update the environment variable for a Lambda function and this the code that I am using currently.
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;
}
Currently this code doesn't work as I am trying to set the environment variable debug to true but it can only be a string and not a boolean.
1 Answer
The documentation is referring to the key and value pair as:
An environment variable is a pair of strings that are stored in a function's version-specific configuration.
You can use:
Environment: {
Variables: {
"debug": "true"
}
}
and check the variable accordingly in your function:
if(process.env.debug === "true") {
console.log("debug is set to true")
}