How can I use environment variables in lambda functions?

Options

How can I use environment variables in lambda functions?

In my Workspace Settings I created a env called "apiKey".How can I use it in the code of my Lambda Function? If I try to log it or use it its always undefined. In the docs it says u can use it everywhere. I also tried $var.apikey and $apiKey.
😒plz help
https://docs.xano.com/working-with-data/variables#environment-variables

Best Answer

  • devben
    devben Member
    Answer ✓
    Options

    ok i figured it out…

    In the "Function Stack" I need to use "Get Environment Variables" before my lambda.

    Notice how I defined "return as envs".

    In the "Lambda Function"´s code I can then simply use the $var keyword.

    //Like so…
    const { apiKey } = $var.envs;
    console.log(`myApiKey: ${apiKey}`); 
    

    👨‍🎓^_^

Answers