Skip to content

Commit cb8b4c8

Browse files
authored
Merge pull request #22 from vkkis93/feat/2.1
Feat/2.1
2 parents 596e7ed + 6f64d2d commit cb8b4c8

File tree

4 files changed

+14
-76
lines changed

4 files changed

+14
-76
lines changed

README.md

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88

99
# serverless-step-functions-offline
10-
:warning: Version 2.0 with breaking changes see [usage](#usage) :warning:
10+
:warning: From v2.1.0 `custom.stepFunctionsOffline` is deprecated :warning:
11+
1112
## Documentation
1213

1314
- [Install](#install)
@@ -46,7 +47,7 @@ sls step-functions-offline
4647

4748
It should rise an error like that:
4849

49-
> Serverless plugin "serverless-step-functions-offline" initialization errored: Please add ENV_VARIABLES to section "custom"
50+
> This command requires the --stateMachine option
5051
5152
# Requirements
5253
This plugin works only with [serverless-step-functions](https://github.com/horike37/serverless-step-functions).
@@ -55,54 +56,6 @@ You must have this plugin installed and correctly specified statemachine definit
5556

5657
Example of statemachine definition you can see [here](https://github.com/horike37/serverless-step-functions#setup).
5758

58-
# Usage
59-
After all steps are done, need to add to section **custom** in serverless.yml the key **stepFunctionsOffline** with properties *stateName*: name of lambda function.
60-
61-
For example:
62-
63-
```yaml
64-
service: ServerlessStepPlugin
65-
frameworkVersion: ">=1.13.0 <2.0.0"
66-
plugins:
67-
- serverless-step-functions-offline
68-
69-
# ...
70-
71-
custom:
72-
stepFunctionsOffline:
73-
stepOne: firstLambda #(v2.0)
74-
# ...
75-
# ...
76-
stepTwo: secondLambda #(v2.0)
77-
78-
functions:
79-
firstLambda:
80-
handler: firstLambda/index.handler
81-
name: TheFirstLambda
82-
secondLambda:
83-
handler: secondLambda/index.handler
84-
name: TheSecondLambda
85-
stepFunctions:
86-
stateMachines:
87-
foo:
88-
definition:
89-
Comment: "An example of the Amazon States Language using wait states"
90-
StartAt: FirstLambda
91-
States:
92-
FirstLambda:
93-
Type: Task
94-
Resource: arn:aws:lambda:eu-west-1:123456789:function:TheFirstLambda
95-
Next: SecondLambda
96-
SecondLambda:
97-
Type: Task
98-
Resource: arn:aws:lambda:eu-west-1:123456789:function:TheSecondLambda
99-
End: true
100-
```
101-
102-
Where:
103-
- `StepOne` is the name of step in state machine
104-
- `firstLambda` is the name of function in section **functions**
105-
10659
# Run Plugin
10760
```bash
10861
sls step-functions-offline --stateMachine={{name}} --event={{path to event file}}

build.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const Promise = require('bluebird');
66
const enumList = require('./enum');
77

88
module.exports = {
9-
109
// findFunctionsPathAndHandler() {
1110
// for (const functionName in this.variables) {
1211
// const functionHandler = this.variables[functionName];
@@ -77,28 +76,21 @@ module.exports = {
7776
return;
7877
}// end of states
7978
this.executionLog(`~~~~~~~~~~~~~~~~~~~~~~~~~~~ ${this.currentStateName} started ~~~~~~~~~~~~~~~~~~~~~~~~~~~`);
80-
const promis = f(event, this.contextObject, this.contextObject.done);
81-
82-
if (promis && promis.then) {
83-
promis.then((data) => {
84-
this.contextObject.done(null, data);
85-
}).catch(err => {
86-
this.contextObject.done(err);
87-
});
79+
f(event, this.contextObject, this.contextObject.done);
8880

89-
return promis;
90-
}
9181
},
9282

9383
_states(currentState, currentStateName) {
9484
switch (currentState.Type) {
9585
case 'Task': // just push task to general array
9686
//before each task restore global default env variables
9787
process.env = Object.assign({}, this.environmentVariables);
98-
let f = this.variables[currentStateName];
99-
f = this.functions[f];
88+
const functionN = currentState.Resource.split(':');
89+
const functionName = functionN[functionN.length - 1];
90+
// let f = this.variables[currentStateName];
91+
const f = this.functions[functionName];
10092
if (!f) {
101-
this.cliLog(`Function "${currentStateName}" does not presented in serverless.yml`);
93+
this.cliLog(`Function "${functionName}" does not presented in serverless.yml`);
10294
process.exit(1);
10395
}
10496
const {handler, filePath} = this._findFunctionPathAndHandler(f.handler);

index.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class StepFunctionsOfflinePlugin {
6666

6767
this._getLocation();
6868
this._checkVersion();
69-
this._checkVariableInYML();
7069
}
7170

7271
_getLocation() {
@@ -85,13 +84,6 @@ class StepFunctionsOfflinePlugin {
8584
}
8685
}
8786

88-
_checkVariableInYML() {
89-
if (!_.has(this.serverless.service, 'custom.stepFunctionsOffline')) {
90-
throw new this.serverless.classes.Error('Please add ENV_VARIABLES to section "custom"');
91-
}
92-
return;
93-
}
94-
9587
isInstalledPluginSLSStepFunctions() {
9688
const plugins = this.serverless.service.plugins;
9789
if (plugins.indexOf('serverless-step-functions') < 0) {
@@ -105,7 +97,8 @@ class StepFunctionsOfflinePlugin {
10597
return this.eventFile = {};
10698
}
10799
try {
108-
this.eventFile = require(path.join(process.cwd(), this.eventFile));
100+
this.eventFile = path.isAbsolute(this.eventFile) ? require(this.eventFile) :
101+
require(path.join(process.cwd(), this.eventFile));
109102
} catch (err) {
110103
throw err;
111104
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-step-functions-offline",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"description": "Serverlesss plugin to support step function offline",
55
"main": "index.js",
66
"author": "viktor.kis <[email protected]>",
@@ -18,11 +18,11 @@
1818
},
1919
"dependencies": {
2020
"bluebird": "^3.5.1",
21-
"lodash": "^4.17.4",
21+
"lodash": "4.17.11",
2222
"moment": "^2.20.1"
2323
},
2424
"devDependencies": {
25-
"eslint": "^4.16.0",
25+
"eslint": "4.17.11",
2626
"chai": "^4.1.2",
2727
"mocha": "^5.0.0",
2828
"nyc": "^11.4.1",

0 commit comments

Comments
 (0)