Skip to content

How to use with AWS Lambda (ie. w/o env vars)? #277

Closed

Description

@GitTom

AWS Lambda does not support environment variables:
http://stackoverflow.com/questions/36230545/how-can-i-use-environmental-variables-on-aws-lambda/

Is there some other way to configure debug that would work with Lambda?

Or is there some other module like debug that works with Lambda?

Activity

  1. darkyen commented on May 31, 2016

    @darkyen

    @GitTom why can't you use dotenv ? .env files are supported pretty much anywhere, and it can load your environment variables to process.env.*,

  2. GitTom commented on Jun 1, 2016

    @GitTom
    Author

    Good suggestion. Looking more closely I see that node-lambda (a module for testing and deploying lambda functions) uses dotenv itself, and from it's docs it looks like it uses it to load stuff into process.env. I'm a little confused about how that jives with the assertion that lambda doesn't support environment variables which I've seen in a few places, but that's just academic now.

    http://stackoverflow.com/a/37033620/150016

  3. freewil commented on Jun 10, 2016

    @freewil
    Contributor

    I'm using Apex, which supports using environment variables with Lambda. It just creates a small wrapper around your lambda handle that sets variables on process.env:

    try {
      var config = require('./.env.json')
      for (var key in config) {
        process.env[key] = config[key]
      }
    } catch (err) {
      // ignore
    }
    
    exports.handle = require('./index').handle
  4. thebigredgeek commented on Dec 14, 2016

    @thebigredgeek
    Contributor

    See #370. Closing

  5. GitTom commented on Jan 19, 2017

    @GitTom
    Author

    For the record, AWS Lambda recently added support for environment variables.

  6. johnelliott commented on May 24, 2017

    @johnelliott

    @GitTom how did you specify the variables? I can't get debug to turn on regardless of what I set in the AWS console.

  7. GitTom commented on May 25, 2017

    @GitTom
    Author

    @johnelliott I'm configuring debug module via the Lambda env variables. On the code tab of my lambda configuration, in "Environment variables" section, I added 'DEBUG' with value '*'.

    Looking around I see that I also have a line "DEBUG=*" in my deploy.env file for node-lambda, and then in my .env file I have "CONFIG_FILE=deploy.env".

  8. johnelliott commented on May 25, 2017

    @johnelliott

    Thanks @GitTom for replying.

    I did a bit of a debug-ectomy on my function for now. I tried setting DEBUG in the AWS console as you mentioned and manually setting process.env.DEBUG in my code. Neither of those worked, so I'll have to give it another shot some time. Thanks 👍

  9. hrushilok commented on Apr 27, 2018

    @hrushilok

    @GitTom
    how do you set environment variables from .env file in following syntax?
    aws lambda create-function \ --environment Variables= \

  10. jamesarosen commented on Oct 7, 2019

    @jamesarosen

    For posterity: Lambda@Edge functions don't support environment variables, so dotenv or similar is the only way to go for those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions