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

Created on 4 May 2016  路  10Comments  路  Source: visionmedia/debug

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?

Most helpful comment

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

All 10 comments

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

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

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

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

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

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

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 馃憤

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jfoclpf picture jfoclpf  路  6Comments

LukeSheard picture LukeSheard  路  3Comments

gdepouilly picture gdepouilly  路  6Comments

BertCatsburg picture BertCatsburg  路  5Comments

Qix- picture Qix-  路  7Comments