2

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
    Are environment variables ever anything but string? Commented Dec 13, 2020 at 20:14

1 Answer 1

7

The documentation https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html 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")
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.