-
Notifications
You must be signed in to change notification settings - Fork 19
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
Allow to run functions with env variables correctly populated #27
base: master
Are you sure you want to change the base?
Conversation
@@ -104,8 +104,6 @@ module.exports = function(S) { | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tszajna0 I'll do it. No worries :)
@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.env
to read variables configured from the environment. They currently crash because functions are not populating this variables correctly.This PR calls the
Runtime.run
function 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.env
will be modified nondeterministically