You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Variables: Pass CLI params to JS file resolvers #4143
The functionality to include and evaluate JavaScript files is pretty neat, though it seems to be kinda inflexible. My proposal would be to pass the options object that is already available into the handler, when evaluating the js file.
The only change necessary seems to be adding the options here.
It's obviously debatable wether this strays too far into the territory of plugins, but it would make my life right now a lot easier without any (for me) obvious drawbacks.
My current situation is that I need to know provider information in a JavaScript file. A smart way would be to simply pass that information with something like ${file(config.js):someVariable(${self:provider.region}). - obviously, that is not yet possible.
A hacky workaround is to pass arguments as environment variables, but that would (to be dynamic) require region in serverless.yml to be set with ${env:REGION} and then reference process.env.REGION in the JavaScript file.
changed the title [-]Passing options to invoked javascript files, with file syntax[/-][+]Variables: Pass CLI params to JS file resolvers[/+]on Dec 29, 2020
I think it's doable to pass CLI params (so what internally is often called options) to JS file variable resolvers, and we'll take it into account when rewriting variable resolver, which is covered here: #7207
Activity
martinjlowm commentedon Mar 23, 2018
Any news on this issue?
My current situation is that I need to know provider information in a JavaScript file. A smart way would be to simply pass that information with something like
${file(config.js):someVariable(${self:provider.region}). - obviously, that is not yet possible.A hacky workaround is to pass arguments as environment variables, but that would (to be dynamic) require region in
serverless.ymlto be set with${env:REGION}and then referenceprocess.env.REGIONin the JavaScript file.[-]Passing options to invoked javascript files, with file syntax[/-][+]Variables: Pass CLI params to JS file resolvers[/+]medikoo commentedon Dec 29, 2020
I think it's doable to pass CLI params (so what internally is often called
options) to JS file variable resolvers, and we'll take it into account when rewriting variable resolver, which is covered here: #7207medikoo commentedon Apr 12, 2021
It's solved with new variables resolver. Check https://www.serverless.com/framework/docs/providers/aws/guide/variables#exporting-a-function