serverless-localstack
Advanced tools
Comparing version 0.4.4 to 0.4.5
{ | ||
"name": "serverless-localstack", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"description": "Connect Serverless to LocalStack!", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -0,1 +1,3 @@ | ||
[](https://travis-ci.org/localstack/serverless-localstack) | ||
# LocalStack Serverless Plugin | ||
@@ -40,9 +42,10 @@ | ||
There are two ways to configure the plugin, via a JSON file or via serverless.yml. There are two supported methods for | ||
configuring the endpoints, globally via the "host" property, or individually. These properties may be mixed, allowing for | ||
There are two ways to configure the plugin, via a JSON file or via `serverless.yml`. | ||
There are two supported methods for configuring the endpoints, globally via the | ||
`host` property, or individually. These properties may be mixed, allowing for | ||
global override support while also override specific endpoints. | ||
A "host" or individual endpoints must be configured or this plugin will be deactivated. | ||
A `host` or individual endpoints must be configured or this plugin will be deactivated. | ||
### Configuring endpoints via serverless.yml | ||
### Configuration via serverless.yml | ||
@@ -58,4 +61,7 @@ ``` | ||
host: http://localhost | ||
stages: | ||
# list of stages for which the plugin should be enabled | ||
- local | ||
endpoints: | ||
# This section can be used for customization but is not strictly needed | ||
# This section is optional - can be used for customizing the target endpoints | ||
S3: http://localhost:4572 | ||
@@ -73,4 +79,13 @@ DynamoDB: http://localhost:4570 | ||
mountCode: True | ||
stages: | ||
local: | ||
... | ||
``` | ||
### Activating the plugin for certain stages | ||
Note the `stages` attribute in the config above. The `serverless-localstack` plugin gets activated if either: | ||
1. `serverless` is invoked with the default stage ("dev") and no `stages` config is provided; or | ||
2. `serverless` is invoked with a `--stage` flag and this stage is included in the `stages` config | ||
### Mounting Lambda code for better performance | ||
@@ -160,4 +175,5 @@ | ||
* v0.4.5: Fix config to activate or deactivate the plugin for certain stages | ||
* v0.4.4: Add `LAMBDA_MOUNT_CWD` configuration for customizing Lambda mount dir | ||
* v0.4.3: Support local mounting of Lambda code to improve performance | ||
* v0.4.0: Add support for local STS |
@@ -23,3 +23,3 @@ const tempy = require('tempy'); | ||
localstack: { | ||
host: 'http://localstack', | ||
host: 'http://localhost', | ||
debug: debug, | ||
@@ -64,3 +64,3 @@ } | ||
execServerless('create --template aws-nodejs', dir) | ||
execServerless('create --template aws-nodejs', dir); | ||
@@ -67,0 +67,0 @@ fs.writeFileSync(`${dir}/serverless.yml`, YAML.stringify(config)); |
@@ -25,2 +25,3 @@ 'use strict'; | ||
let sandbox; | ||
let defaultPluginState = {}; | ||
let config = { | ||
@@ -63,3 +64,3 @@ host: 'http://localhost', | ||
serverless.service.custom = {}; | ||
instance = new LocalstackPlugin(serverless, {}); | ||
instance = new LocalstackPlugin(serverless, defaultPluginState); | ||
simulateBeforeDeployHooks(instance) | ||
@@ -84,3 +85,3 @@ }); | ||
}; | ||
instance = new LocalstackPlugin(serverless, {}) | ||
instance = new LocalstackPlugin(serverless, defaultPluginState); | ||
simulateBeforeDeployHooks(instance); | ||
@@ -102,3 +103,3 @@ }); | ||
let plugin = new LocalstackPlugin(serverless, {}); | ||
let plugin = new LocalstackPlugin(serverless, defaultPluginState); | ||
simulateBeforeDeployHooks(plugin); | ||
@@ -125,3 +126,6 @@ expect(plugin.endpoints).to.be.empty; | ||
let plugin = () => {let pluginInstance = new LocalstackPlugin(serverless, {}); pluginInstance.readConfig() } | ||
let plugin = () => { | ||
let pluginInstance = new LocalstackPlugin(serverless, defaultPluginState); | ||
pluginInstance.readConfig(); | ||
} | ||
@@ -135,3 +139,6 @@ expect(plugin).to.throw('Endpoint: "missing.json" is invalid:') | ||
} | ||
let plugin = () => {let pluginInstance = new LocalstackPlugin(serverless, {}); pluginInstance.readConfig() } | ||
let plugin = () => { | ||
let pluginInstance = new LocalstackPlugin(serverless, defaultPluginState); | ||
pluginInstance.readConfig(); | ||
} | ||
expect(plugin).to.throw(/Endpoint: "README.md" is invalid:/) | ||
@@ -160,3 +167,3 @@ }); | ||
} | ||
} | ||
@@ -175,3 +182,3 @@ | ||
let request = sinon.stub(awsProvider, 'request'); | ||
instance = new LocalstackPlugin(serverless, {}) | ||
instance = new LocalstackPlugin(serverless, defaultPluginState) | ||
simulateBeforeDeployHooks(instance); | ||
@@ -190,3 +197,3 @@ | ||
let request = sinon.stub(awsProvider, 'request'); | ||
instance = new LocalstackPlugin(serverless, {}) | ||
instance = new LocalstackPlugin(serverless, defaultPluginState) | ||
awsProvider.request('S3','validateTemplate',{}); | ||
@@ -193,0 +200,0 @@ |
@@ -7,3 +7,6 @@ 'use strict'; | ||
// Default stage used by serverless | ||
const defaultStage = 'dev'; | ||
class LocalstackPlugin { | ||
@@ -14,2 +17,8 @@ constructor(serverless, options) { | ||
this.readConfig(); | ||
if (!this.isActive()) { | ||
return; | ||
} | ||
this.commands = { | ||
@@ -72,7 +81,5 @@ deploy: {} | ||
} | ||
this.skipIfMountLambda('AwsCompileFunctions', 'compileFunction', compileFunction) | ||
this.skipIfMountLambda('AwsDeploy', 'extendedValidate') | ||
this.skipIfMountLambda('AwsDeploy', 'uploadFunctionsAndLayers') | ||
this.readConfig(); | ||
this.skipIfMountLambda('AwsCompileFunctions', 'compileFunction', compileFunction); | ||
this.skipIfMountLambda('AwsDeploy', 'extendedValidate'); | ||
this.skipIfMountLambda('AwsDeploy', 'uploadFunctionsAndLayers'); | ||
} | ||
@@ -115,4 +122,4 @@ | ||
//Get the target deployment stage | ||
this.config.stage = "" | ||
this.config.options_stage = this.options.stage || undefined | ||
this.config.stage = ""; | ||
this.config.options_stage = this.options.stage || undefined; | ||
@@ -128,2 +135,11 @@ //If the target stage is listed in config.stages use the serverless-localstack-plugin | ||
isActive() { | ||
// Activate the plugin if either: | ||
// (1) serverless is invoked with the default stage ("dev") and no `stages` config is provided; or | ||
// (2) serverless is invoked with a --stage flag and this stage is included in the `stages` config | ||
const noStageUsed = this.config.stages === undefined && (this.options.stage || defaultStage) == defaultStage; | ||
const includedInStages = this.config.stages && this.config.stages.includes(this.options.stage); | ||
return noStageUsed || includedInStages; | ||
} | ||
getStageVariable() { | ||
@@ -133,7 +149,8 @@ this.debug("config.options_stage: " + this.config.options_stage); | ||
this.debug("serverless.service.provider.stage: " + this.serverless.service.provider.stage); | ||
this.config.stage = this.config.options_stage || this.serverless.service.custom.stage || this.serverless.service.provider.stage | ||
this.config.stage = this.config.options_stage || this.serverless.service.custom.stage || this.serverless.service.provider.stage; | ||
this.debug("config.stage: " + this.config.stage); | ||
} | ||
reconfigureAWS() { | ||
if(this.config.stages === undefined || this.config.stages.indexOf(this.config.stage) > -1){ | ||
if(this.isActive()) { | ||
this.log('Using serverless-localstack'); | ||
@@ -169,5 +186,3 @@ const host = this.config.host; | ||
this.log("Skipping serverless-localstack:\ncustom.localstack.stages: " + | ||
JSON.stringify(this.config.stages) + | ||
"\nstage: " + | ||
this.config.stage | ||
JSON.stringify(this.config.stages) + "\nstage: " + this.config.stage | ||
) | ||
@@ -174,0 +189,0 @@ } |
36798
864
176