Skip to content

Commit 621f5cc

Browse files
committed
Delay reading config until package:initialize hook
This lets serverless variables be resolved before the config.layerConfig object is parsed. This fixes #3.
1 parent dcb4cec commit 621f5cc

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

LayerManagerPlugin.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,23 @@ function getConfig(serverless) {
4444
class LayerManagerPlugin {
4545
constructor(sls, options = {}) {
4646
this.level = options.v || options.verbose ? 'verbose' : LOG_LEVEL;
47-
this.config = getConfig(sls);
4847

4948
info(this, `Invoking layer-manager plugin`);
50-
verbose(this, `Config: `, this.config);
5149

5250
this.hooks = {
53-
'package:initialize': () => this.installLayers(sls),
51+
'package:initialize': () => {
52+
this.init(sls);
53+
this.installLayers(sls)
54+
},
5455
'before:deploy:deploy': () => this.transformLayerResources(sls)
5556
};
5657
}
5758

59+
init(sls) {
60+
this.config = getConfig(sls);
61+
verbose(this, `Config: `, this.config);
62+
}
63+
5864
installLayer(path) {
5965
const nodeLayerPath = `${path}/nodejs`;
6066

@@ -141,4 +147,4 @@ class LayerManagerPlugin {
141147
}
142148
}
143149

144-
module.exports = LayerManagerPlugin;
150+
module.exports = LayerManagerPlugin;

examples/example-layer-service/serverless.yml

+7-6
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ functions:
2020
# Note the reference being the TitleCase representation of the layer id followed by "LambdaLayer"
2121
- {Ref: MyLibLambdaLayer}
2222

23-
#custom:
24-
# layerConfig:
25-
# installLayers: <boolean>
26-
# exportLayers: <boolean>
27-
# upgradeLayerReferences: <boolean>
28-
# exportPrefix: <prefix used for the names of the exported layers>
23+
custom:
24+
foo: FOO
25+
layerConfig:
26+
installLayers: true
27+
exportLayers: true
28+
upgradeLayerReferences: true
29+
exportPrefix: ${self:service}-${self:custom.foo}- # prefix used for the names of the exported layers
2930

0 commit comments

Comments
 (0)