Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
GitTom opened this issue May 4, 2016 · 10 comments
Closed

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

GitTom opened this issue May 4, 2016 · 10 comments

Comments

@GitTom
Copy link

GitTom commented May 4, 2016

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?

@darkyen
Copy link

darkyen commented May 31, 2016

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

@GitTom
Copy link
Author

GitTom commented Jun 1, 2016

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

@freewil
Copy link
Contributor

freewil commented Jun 10, 2016

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

@thebigredgeek
Copy link
Contributor

See #370. Closing

@GitTom
Copy link
Author

GitTom commented Jan 19, 2017

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

@johnelliott
Copy link

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

@GitTom
Copy link
Author

GitTom commented May 25, 2017

@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".

@johnelliott
Copy link

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 👍

@hrushilok
Copy link

hrushilok commented Apr 27, 2018

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

@jamesarosen
Copy link

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
Labels
None yet
Development

No branches or pull requests

7 participants