Skip to content

Commit

Permalink
Delay reading config until package:initialize hook
Browse files Browse the repository at this point in the history
This lets serverless variables be resolved before the config.layerConfig object is parsed.
This fixes #3.
  • Loading branch information
henhal committed Jan 2, 2020
1 parent dcb4cec commit 621f5cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
14 changes: 10 additions & 4 deletions LayerManagerPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,23 @@ function getConfig(serverless) {
class LayerManagerPlugin {
constructor(sls, options = {}) {
this.level = options.v || options.verbose ? 'verbose' : LOG_LEVEL;
this.config = getConfig(sls);

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

this.hooks = {
'package:initialize': () => this.installLayers(sls),
'package:initialize': () => {
this.init(sls);
this.installLayers(sls)
},
'before:deploy:deploy': () => this.transformLayerResources(sls)
};
}

init(sls) {
this.config = getConfig(sls);
verbose(this, `Config: `, this.config);
}

installLayer(path) {
const nodeLayerPath = `${path}/nodejs`;

Expand Down Expand Up @@ -141,4 +147,4 @@ class LayerManagerPlugin {
}
}

module.exports = LayerManagerPlugin;
module.exports = LayerManagerPlugin;
13 changes: 7 additions & 6 deletions examples/example-layer-service/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ functions:
# Note the reference being the TitleCase representation of the layer id followed by "LambdaLayer"
- {Ref: MyLibLambdaLayer}

#custom:
# layerConfig:
# installLayers: <boolean>
# exportLayers: <boolean>
# upgradeLayerReferences: <boolean>
# exportPrefix: <prefix used for the names of the exported layers>
custom:
foo: FOO
layerConfig:
installLayers: true
exportLayers: true
upgradeLayerReferences: true
exportPrefix: ${self:service}-${self:custom.foo}- # prefix used for the names of the exported layers

0 comments on commit 621f5cc

Please sign in to comment.