Skip to content

Commit a9e6a79

Browse files
authored
Merge pull request serverless#4743 from svdgraaf/feature/pass-serverless-variable
Pass serverless variable when calling function in referenced file
2 parents 44fd29d + 63c57e7 commit a9e6a79

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

docs/providers/aws/guide/variables.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ functions:
285285

286286
You can reference JavaScript files to add dynamic data into your variables.
287287

288-
References can be either named or unnamed exports. To use the exported `someModule` in `myFile.js` you'd use the following code `${file(./myFile.js):someModule}`. For an unnamed export you'd write `${file(./myFile.js)}`.
288+
References can be either named or unnamed exports. To use the exported `someModule` in `myFile.js` you'd use the following code `${file(./myFile.js):someModule}`. For an unnamed export you'd write `${file(./myFile.js)}`. The first argument to your export will be a reference to the Serverless object, containing your configuration.
289289

290290
Here are other examples:
291291

@@ -299,7 +299,9 @@ module.exports.rate = () => {
299299

300300
```js
301301
// config.js
302-
module.exports = () => {
302+
module.exports = (serverless) => {
303+
serverless.cli.consoleLog('You can access Serverless config and methods as well!');
304+
303305
return {
304306
property1: 'some value',
305307
property2: 'some other value'

lib/classes/Variables.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ class Variables {
591591
].join('');
592592
return BbPromise.reject(new this.serverless.classes.Error(errorMessage));
593593
}
594-
valueToPopulate = returnValueFunction.call(jsFile);
594+
valueToPopulate = returnValueFunction.call(jsFile, this.serverless);
595595

596596
return BbPromise.resolve(valueToPopulate).then((valueToPopulateResolved) => {
597597
let deepProperties = variableString.replace(matchedFileRefString, '');

0 commit comments

Comments
 (0)