aws-local-stepfunctions 0.3.2 → 0.5.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 +55 -97
- package/build/main.browser.esm.js +24726 -0
- package/build/main.d.ts +100 -120
- package/build/main.node.cjs +1002 -0
- package/build/main.node.esm.js +964 -0
- package/package.json +28 -23
- package/build/main.cjs +0 -5
- package/build/main.esm.js +0 -5
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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
|
-
This package lets you run AWS Step Functions locally
|
|
5
|
+
This package lets you run AWS Step Functions locally, both in Node.js and in the browser!
|
|
6
6
|
|
|
7
7
|
> NOTE: This is a work in progress. Some features defined in the specification might not be supported at all yet or might have limited support.
|
|
8
8
|
|
|
@@ -14,9 +14,11 @@ This package lets you run AWS Step Functions locally on your machine!
|
|
|
14
14
|
- [Node.js](#nodejs)
|
|
15
15
|
- [CommonJS](#commonjs)
|
|
16
16
|
- [ES Module](#es-module)
|
|
17
|
+
- [Browser](#browser)
|
|
17
18
|
- [API](#api)
|
|
18
|
-
- [Constructor](#constructor-new-statemachinedefinition-
|
|
19
|
+
- [Constructor](#constructor-new-statemachinedefinition-statemachineoptions)
|
|
19
20
|
- [StateMachine.run](#statemachineruninput-options)
|
|
21
|
+
- [Examples](#examples)
|
|
20
22
|
- [License](#license)
|
|
21
23
|
|
|
22
24
|
## Features
|
|
@@ -31,8 +33,6 @@ npm install aws-local-stepfunctions
|
|
|
31
33
|
|
|
32
34
|
## Importing
|
|
33
35
|
|
|
34
|
-
Currently, the only supported environment to import the package is Node.js. Browser support is not available yet.
|
|
35
|
-
|
|
36
36
|
### Node.js
|
|
37
37
|
|
|
38
38
|
#### CommonJS
|
|
@@ -47,20 +47,44 @@ const { StateMachine } = require('aws-local-stepfunctions');
|
|
|
47
47
|
import { StateMachine } from 'aws-local-stepfunctions';
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
### Browser
|
|
51
|
+
|
|
52
|
+
You can import the bundled package directly into a browser script as an ES module, from one of the following CDNs:
|
|
53
|
+
|
|
54
|
+
> NOTE: The following examples will import the latest package version. Refer to the CDNs websites to know about other ways in which you can specify the package URL (for example, to import a specific version).
|
|
55
|
+
|
|
56
|
+
#### [unpkg](https://unpkg.com/)
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
import { StateMachine } from 'https://unpkg.com/aws-local-stepfunctions';
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
#### [jsDelivr](https://www.jsdelivr.com/)
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
import { StateMachine } from 'https://cdn.jsdelivr.net/npm/aws-local-stepfunctions/build/main.browser.esm.js';
|
|
66
|
+
```
|
|
67
|
+
|
|
50
68
|
## API
|
|
51
69
|
|
|
52
|
-
### Constructor: `new StateMachine(definition[,
|
|
70
|
+
### Constructor: `new StateMachine(definition[, stateMachineOptions])`
|
|
53
71
|
|
|
54
72
|
#### Parameters
|
|
55
73
|
|
|
56
74
|
The constructor takes the following parameters:
|
|
57
75
|
|
|
58
76
|
- `definition`: The Amazon States Language definition of the state machine.
|
|
59
|
-
- `
|
|
60
|
-
- `
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
77
|
+
- `stateMachineOptions?`:
|
|
78
|
+
- `validationOptions?`: An object that specifies how the definition should be validated.
|
|
79
|
+
- `checkPaths`: If set to `false`, won't validate JSONPaths.
|
|
80
|
+
- `checkArn`: If set to `false`, won't validate ARN syntax in `Task` states.
|
|
81
|
+
- `awsConfig?`: An object that specifies the AWS region and credentials to use when invoking a Lambda function in a `Task` state. If not set, the AWS config will be resolved based on the [credentials provider chain](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html) of the AWS SDK for JavaScript V3. You don't need to use this option if you have a [shared config/credentials file](https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html) (for example, if you have the [AWS CLI](https://aws.amazon.com/cli/) installed) or if you use a local override for all of your `Task` states.
|
|
82
|
+
- `region`: The AWS region where the Lambda functions are created.
|
|
83
|
+
- `credentials`: An object that specifies which type of credentials to use.
|
|
84
|
+
- `cognitoIdentityPool`: An object that specifies the Cognito Identity Pool to use for requesting credentials.
|
|
85
|
+
- `accessKeys`: An object that specifies the [Access Key ID and Secret Access Key](https://docs.aws.amazon.com/IAM/latest/UserGuide/security-creds.html#sec-access-keys-and-secret-access-keys) to use as credentials.
|
|
86
|
+
|
|
87
|
+
The constructor will attempt to validate the definition by default, unless the `validationOptions` property is specified. If the definition is not valid, an error will be thrown.
|
|
64
88
|
|
|
65
89
|
#### Example
|
|
66
90
|
|
|
@@ -80,7 +104,9 @@ const machineDefinition = {
|
|
|
80
104
|
};
|
|
81
105
|
|
|
82
106
|
// Instantiate a new state machine with the given definition and don't validate JSONPaths.
|
|
83
|
-
const stateMachine = new StateMachine(machineDefinition, {
|
|
107
|
+
const stateMachine = new StateMachine(machineDefinition, {
|
|
108
|
+
validationOptions: { checkPaths: false },
|
|
109
|
+
});
|
|
84
110
|
```
|
|
85
111
|
|
|
86
112
|
### `StateMachine.run(input[, options])`
|
|
@@ -95,15 +121,13 @@ Each execution is independent of all others, meaning that you can concurrently c
|
|
|
95
121
|
#### Parameters
|
|
96
122
|
|
|
97
123
|
- `input`: The initial input to pass to the state machine. This can be any valid JSON value.
|
|
98
|
-
- `options
|
|
99
|
-
- `overrides
|
|
100
|
-
- `taskResourceLocalHandlers
|
|
101
|
-
- `waitTimeOverrides
|
|
102
|
-
- `noThrowOnAbort
|
|
124
|
+
- `options?`:
|
|
125
|
+
- `overrides?`: An object to override the behavior of certain states:
|
|
126
|
+
- `taskResourceLocalHandlers?`: Overrides the resource of the specified `Task` states to run a local function.
|
|
127
|
+
- `waitTimeOverrides?`: Overrides the wait duration of the specified `Wait` states. The specifed override duration should be in milliseconds.
|
|
128
|
+
- `noThrowOnAbort?`: If this option is set to `true`, aborting the execution will simply return `null` as result instead of throwing.
|
|
103
129
|
|
|
104
|
-
####
|
|
105
|
-
|
|
106
|
-
##### Example without `options`:
|
|
130
|
+
#### Basic example:
|
|
107
131
|
|
|
108
132
|
```js
|
|
109
133
|
import { StateMachine } from 'aws-local-stepfunctions';
|
|
@@ -127,89 +151,23 @@ const result = await execution.result; // wait until the execution finishes to g
|
|
|
127
151
|
console.log(result); // log the result of the execution
|
|
128
152
|
```
|
|
129
153
|
|
|
130
|
-
|
|
154
|
+
## Examples
|
|
131
155
|
|
|
132
|
-
|
|
133
|
-
import { StateMachine } from 'aws-local-stepfunctions';
|
|
156
|
+
You can check more examples and options usage in the [examples](/examples) directory.
|
|
134
157
|
|
|
135
|
-
|
|
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
|
-
};
|
|
155
|
-
|
|
156
|
-
function addNumbersLocal(input) {
|
|
157
|
-
return input.num1 + input.num2;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const stateMachine = new StateMachine(machineDefinition);
|
|
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
|
-
});
|
|
158
|
+
To run the examples, clone the repo, install the dependencies and build the project:
|
|
172
159
|
|
|
173
|
-
|
|
174
|
-
|
|
160
|
+
```sh
|
|
161
|
+
git clone https://github.com/nibble-4bits/aws-local-stepfunctions.git --depth 1
|
|
162
|
+
cd aws-local-stepfunctions
|
|
163
|
+
npm install
|
|
164
|
+
npm run build
|
|
175
165
|
```
|
|
176
166
|
|
|
177
|
-
|
|
167
|
+
Then run whichever example you want:
|
|
178
168
|
|
|
179
|
-
```
|
|
180
|
-
|
|
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
|
-
};
|
|
192
|
-
|
|
193
|
-
const stateMachine = new StateMachine(machineDefinition);
|
|
194
|
-
const myInput = { value1: 'hello', value2: 123, value3: true };
|
|
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
|
-
}
|
|
169
|
+
```sh
|
|
170
|
+
node examples/abort-execution.js
|
|
213
171
|
```
|
|
214
172
|
|
|
215
173
|
## License
|