Allow to run functions with env variables correctly populated#27
Allow to run functions with env variables correctly populated#27marcosnils wants to merge 1 commit into
Conversation
| return functions.forEach(function(fun) { | ||
| if( -1 !== fun.getRuntime().getName().indexOf('nodejs') ) { | ||
| // Override s-function.json defined environment! | ||
| Object.getPrototypeOf( fun.getRuntime() ).getEnvVars = ()=> BbPromise.resolve( {} ); |
There was a problem hiding this comment.
It may be made optional, but not removed, because it's really useful to pass local config (different form AWS) via env and not have it overriden by SLS Function.run, e.g. https://github.com/serverless/serverless/blob/master/lib/RuntimeNode.js#L48
There was a problem hiding this comment.
@tszajna0 I see what you mean but shouldn't the serve plugin work the same was as serverless core does?. In serverless core you can't override the variables defined in your s-function.json file. You need to properly configure your stage variables to make them work.
There was a problem hiding this comment.
@marcosnils let me put it opposite way: I wish I could easily specify my own env when locally running functions in SLS, unfortunately I have to properly configure stage variables in a different way than I'd deploy to AWS.
IMO it's useful to mimic sls behavior as close as possible and it's also useful to be able to alter it slightly. Then having a switch between these two would make everyone happy, I suppose. If you agree, then the question is shall I do it or would you?
|
@marcosnils populating env from s-function.json can be made optional, but it'll be painful to make it mandatory; see my comments inline. note: you're right on different env for each function; AFAIR it wasn't possible with older sls. IMO it's not a piece of cake to have this supported in serverless-serve under current design, anyway you may try if you'd like to. |
My lambda functions use
process.envto read variables configured from the environment. They currently crash because functions are not populating this variables correctly.This PR calls the
Runtime.runfunction which properly initializes env variables for the specific function.note: if multiple functions use the same env variables and functions are executed concurrently, unknown errors may happen as
process.envwill be modified nondeterministically