Can Aws Lambda's Environment Variable Be Set to a Boolean Value?

Can Aws Lambda's Environment Variable Be Set to a Boolean Value?

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

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")
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance
Author

Marcus Vance

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.