Skip to content

Commit 39bad3f

Browse files
committed
return old implementation of loading functions
1 parent 43a8c9d commit 39bad3f

File tree

3 files changed

+65
-17
lines changed

3 files changed

+65
-17
lines changed

README.md

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
[![Maintainability](https://api.codeclimate.com/v1/badges/b321644ef368976aee12/maintainability)](https://codeclimate.com/github/vkkis93/serverless-step-functions-offline/maintainability)
55
[![NPM](https://nodei.co/npm/serverless-step-functions-offline.png)](https://nodei.co/npm/serverless-step-functions-offline/)
66

7-
87
# serverless-step-functions-offline
9-
:warning: From v2.1.0 `custom.stepFunctionsOffline` is deprecated :warning:
10-
8+
:warning: Version 2.0 with breaking changes see [usage](#usage) :warning:
119
## Documentation
1210

1311
- [Install](#install)
@@ -18,7 +16,6 @@
1816
- [What does plugin support](#what-does-plugin-support)
1917
- [Usage with serverless-wepback](#usage-with-serverless-webpack)
2018

21-
If you use it, ⭐️ it!
2219

2320
# Install
2421
Using NPM:
@@ -46,7 +43,7 @@ sls step-functions-offline
4643

4744
It should rise an error like that:
4845

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

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

55+
# Usage
56+
After all steps are done, need to add to section **custom** in serverless.yml the key **stepFunctionsOffline** with properties *stateName*: name of lambda function.
57+
58+
For example:
59+
60+
```yaml
61+
service: ServerlessStepPlugin
62+
frameworkVersion: ">=1.13.0 <2.0.0"
63+
plugins:
64+
- serverless-step-functions-offline
65+
66+
# ...
67+
68+
custom:
69+
stepFunctionsOffline:
70+
stepOne: firstLambda #(v2.0)
71+
# ...
72+
# ...
73+
stepTwo: secondLambda #(v2.0)
74+
75+
functions:
76+
firstLambda:
77+
handler: firstLambda/index.handler
78+
name: TheFirstLambda
79+
secondLambda:
80+
handler: secondLambda/index.handler
81+
name: TheSecondLambda
82+
stepFunctions:
83+
stateMachines:
84+
foo:
85+
definition:
86+
Comment: "An example of the Amazon States Language using wait states"
87+
StartAt: FirstLambda
88+
States:
89+
FirstLambda:
90+
Type: Task
91+
Resource: arn:aws:lambda:eu-west-1:123456789:function:TheFirstLambda
92+
Next: SecondLambda
93+
SecondLambda:
94+
Type: Task
95+
Resource: arn:aws:lambda:eu-west-1:123456789:function:TheSecondLambda
96+
End: true
97+
```
98+
99+
Where:
100+
- `StepOne` is the name of step in state machine
101+
- `firstLambda` is the name of function in section **functions**
102+
58103
# Run Plugin
59104
```bash
60105
sls step-functions-offline --stateMachine={{name}} --event={{path to event file}}
@@ -99,11 +144,6 @@ precedes `serverless-step-functions-offline` as the order is important:
99144
- [x] Fixing bugs
100145
- [x] Support Pass, Fail, Succeed
101146
- [x] Integration with serverless-webpack
102-
- [ ] Add unit tests - to make plugin stable (next step)
147+
- [ ] Add unit tests - to make plugin stable (next step)
103148
- [ ] Support fields *Retry*, *Catch*
104-
- [ ] Support other languages except node.js
105-
106-
107-
# License
108-
109-
MIT
149+
- [ ] Support other languages except node.js

build.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,10 @@ module.exports = {
8585
case 'Task': // just push task to general array
8686
//before each task restore global default env variables
8787
process.env = Object.assign({}, this.environmentVariables);
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];
88+
let f = this.variables[currentStateName];
89+
f = this.functions[f];
9290
if (!f) {
93-
this.cliLog(`Function "${functionName}" does not presented in serverless.yml`);
91+
this.cliLog(`Function "${currentStateName}" does not presented in serverless.yml`);
9492
process.exit(1);
9593
}
9694
const {handler, filePath} = this._findFunctionPathAndHandler(f.handler);

index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ class StepFunctionsOfflinePlugin {
6666

6767
this._getLocation();
6868
this._checkVersion();
69+
this._checkVariableInYML();
70+
6971
}
7072

73+
7174
_getLocation() {
7275
if (this.options.location) {
7376
this.location = path.join(process.cwd(), this.options.location);
@@ -84,6 +87,13 @@ class StepFunctionsOfflinePlugin {
8487
}
8588
}
8689

90+
_checkVariableInYML() {
91+
if (!_.has(this.serverless.service, 'custom.stepFunctionsOffline')) {
92+
throw new this.serverless.classes.Error('Please add ENV_VARIABLES to section "custom"');
93+
}
94+
return;
95+
}
96+
8797
isInstalledPluginSLSStepFunctions() {
8898
const plugins = this.serverless.service.plugins;
8999
if (plugins.indexOf('serverless-step-functions') < 0) {

0 commit comments

Comments
 (0)