aws-local-stepfunctions 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -81
- package/build/main.cjs +927 -5
- package/build/main.d.ts +39 -79
- package/build/main.esm.js +889 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# AWS Local Step Functions
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A TypeScript implementation of the [Amazon States Language specification](https://states-language.net/spec.html).
|
|
4
4
|
|
|
5
5
|
This package lets you run AWS Step Functions locally on your machine!
|
|
6
6
|
|
|
@@ -17,6 +17,7 @@ This package lets you run AWS Step Functions locally on your machine!
|
|
|
17
17
|
- [API](#api)
|
|
18
18
|
- [Constructor](#constructor-new-statemachinedefinition-validationoptions)
|
|
19
19
|
- [StateMachine.run](#statemachineruninput-options)
|
|
20
|
+
- [Examples](#examples)
|
|
20
21
|
- [License](#license)
|
|
21
22
|
|
|
22
23
|
## Features
|
|
@@ -101,9 +102,7 @@ Each execution is independent of all others, meaning that you can concurrently c
|
|
|
101
102
|
- `waitTimeOverrides`: Overrides the wait duration of the specified `Wait` states. The specifed override duration should be in milliseconds.
|
|
102
103
|
- `noThrowOnAbort`: If this option is set to `true`, aborting the execution will simply return `null` as result instead of throwing.
|
|
103
104
|
|
|
104
|
-
####
|
|
105
|
-
|
|
106
|
-
##### Example without `options`:
|
|
105
|
+
#### Basic example:
|
|
107
106
|
|
|
108
107
|
```js
|
|
109
108
|
import { StateMachine } from 'aws-local-stepfunctions';
|
|
@@ -127,89 +126,23 @@ const result = await execution.result; // wait until the execution finishes to g
|
|
|
127
126
|
console.log(result); // log the result of the execution
|
|
128
127
|
```
|
|
129
128
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
```js
|
|
133
|
-
import { StateMachine } from 'aws-local-stepfunctions';
|
|
134
|
-
|
|
135
|
-
const machineDefinition = {
|
|
136
|
-
StartAt: 'Hello World',
|
|
137
|
-
States: {
|
|
138
|
-
'Hello World': {
|
|
139
|
-
Type: 'Task',
|
|
140
|
-
Resource: 'arn:aws:lambda:us-east-1:123456789012:function:HelloWorld',
|
|
141
|
-
Next: 'AddNumbers',
|
|
142
|
-
},
|
|
143
|
-
AddNumbers: {
|
|
144
|
-
Type: 'Task',
|
|
145
|
-
Resource: 'arn:aws:lambda:us-east-1:123456789012:function:AddNumbers',
|
|
146
|
-
Next: 'Wait10Seconds',
|
|
147
|
-
},
|
|
148
|
-
Wait10Seconds: {
|
|
149
|
-
Type: 'Wait',
|
|
150
|
-
Seconds: 10,
|
|
151
|
-
End: true,
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
};
|
|
129
|
+
## Examples
|
|
155
130
|
|
|
156
|
-
|
|
157
|
-
return input.num1 + input.num2;
|
|
158
|
-
}
|
|
131
|
+
You can check more examples and options usage in the [examples](/examples) directory.
|
|
159
132
|
|
|
160
|
-
|
|
161
|
-
const myInput = { value1: 'hello', value2: 123, value3: true };
|
|
162
|
-
const execution = stateMachine.run(myInput, {
|
|
163
|
-
overrides: {
|
|
164
|
-
taskResourceLocalHandlers: {
|
|
165
|
-
AddNumbers: addNumbersLocal, // call the `addNumbersLocal` function instead of invoking the Lambda function specified for the `AddNumbers` state
|
|
166
|
-
},
|
|
167
|
-
waitTimeOverrides: {
|
|
168
|
-
Wait10Seconds: 500, // wait for 500 milliseconds instead of the 10 seconds specified in the `Wait10Seconds` state
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
});
|
|
133
|
+
To run the examples, clone the repo, install the dependencies and build the project:
|
|
172
134
|
|
|
173
|
-
|
|
174
|
-
|
|
135
|
+
```sh
|
|
136
|
+
git clone https://github.com/nibble-4bits/aws-local-stepfunctions.git --depth 1
|
|
137
|
+
cd aws-local-stepfunctions
|
|
138
|
+
npm install
|
|
139
|
+
npm run build
|
|
175
140
|
```
|
|
176
141
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
```js
|
|
180
|
-
import { StateMachine, ExecutionAbortedError } from 'aws-local-stepfunctions';
|
|
181
|
-
|
|
182
|
-
const machineDefinition = {
|
|
183
|
-
StartAt: 'Hello World',
|
|
184
|
-
States: {
|
|
185
|
-
'Hello World': {
|
|
186
|
-
Type: 'Task',
|
|
187
|
-
Resource: 'arn:aws:lambda:us-east-1:123456789012:function:HelloWorld',
|
|
188
|
-
End: true,
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
};
|
|
142
|
+
Then run whichever example you want:
|
|
192
143
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const execution = stateMachine.run(myInput);
|
|
196
|
-
|
|
197
|
-
// abort the execution after 3 seconds
|
|
198
|
-
setTimeout(() => {
|
|
199
|
-
execution.abort();
|
|
200
|
-
}, 3000);
|
|
201
|
-
|
|
202
|
-
try {
|
|
203
|
-
const result = await execution.result;
|
|
204
|
-
console.log(result);
|
|
205
|
-
} catch (e) {
|
|
206
|
-
if (e instanceof ExecutionAbortedError) {
|
|
207
|
-
// since execution was aborted, type of error is `ExecutionAbortedError`
|
|
208
|
-
console.log('Execution was aborted');
|
|
209
|
-
} else {
|
|
210
|
-
console.error('Some other error', e);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
144
|
+
```sh
|
|
145
|
+
node examples/abort-execution.js
|
|
213
146
|
```
|
|
214
147
|
|
|
215
148
|
## License
|