aws-local-stepfunctions 1.3.0 → 2.0.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 CHANGED
@@ -41,6 +41,7 @@ This package lets you run AWS Step Functions state machines completely locally,
41
41
  - [Overriding Task and Wait states](#overriding-task-and-wait-states)
42
42
  - [Task state override](#task-state-override)
43
43
  - [Wait state override](#wait-state-override)
44
+ - [Retry field pause override](#retry-field-pause-override)
44
45
  - [Passing a custom Context Object](#passing-a-custom-context-object)
45
46
  - [Disabling ASL validations](#disabling-asl-validations)
46
47
  - [Exit codes](#exit-codes)
@@ -362,6 +363,54 @@ local-sfn \
362
363
 
363
364
  This command would execute the state machine, and override `Wait` states `WaitResponse` and `PauseUntilSignal` to pause the execution for 1500 and 250 milliseconds, respectively. The `Delay` state wouldn't be paused at all, since the override value is set to 0.
364
365
 
366
+ #### Retry field pause override
367
+
368
+ To override the duration of the pause in the `Retry` field of a state, pass the `-r, --override-retry` option. This option takes as value the name of the state whose `Retry` field you want to override, and a number that represents the amount in milliseconds that you want to pause the execution for before retrying the state. The state name and the milliseconds amount must be separated by a colon `:`.
369
+
370
+ For example, suppose the state machine definition contains a state called `TaskToRetry` that is defined as follows:
371
+
372
+ ```json
373
+ {
374
+ "Type": "Task",
375
+ "Resource": "arn:aws:lambda:us-east-1:123456789012:function:HelloWorld",
376
+ "Retry": [
377
+ { "ErrorEquals": ["States.Timeout", "SyntaxError"] },
378
+ { "ErrorEquals": ["RangeError"] },
379
+ { "ErrorEquals": ["States.ALL"] }
380
+ ],
381
+ "End": true
382
+ }
383
+ ```
384
+
385
+ Then, the following command is run:
386
+
387
+ ```sh
388
+ local-sfn -f state-machine.json -r TaskToRetry:100 '{ "num1": 1, "num2": 2 }'
389
+ ```
390
+
391
+ This command would execute the state machine, and if the `TaskToRetry` state fails, the execution would be paused for 100 milliseconds before retrying the state again, disregarding the `IntervalSeconds`, `BackoffRate`, `MaxDelaySeconds`, and `JitterStrategy` fields that could've been specified in any of the `Retry` field retriers.
392
+
393
+ Alternatively, you can also pass a list of comma-separated numbers as value, to override the duration of specific retriers, for instance:
394
+
395
+ ```sh
396
+ local-sfn -f state-machine.json -r TaskToRetry:100,-1,20 '{ "num1": 1, "num2": 2 }'
397
+ ```
398
+
399
+ The above command would pause the execution for 100 milliseconds if the state error is matched by the first retrier and it would pause for 20 milliseconds if the error matches the third retrier. Note that a -1 was passed for the second retrier. This means that the pause duration of the second retrier will not be overridden, instead, it will be calculated as usually with the `IntervalSeconds` and the other retrier fields, or use the default values if said fields are not specified.
400
+
401
+ Furthermore, you can pass this option multiple times, to override the `Retry` fields in multiple states. For example:
402
+
403
+ ```sh
404
+ local-sfn \
405
+ -f state-machine.json \
406
+ -r SendRequest:1500 \
407
+ -r ProcessData:250 \
408
+ -r MapResponses:0 \
409
+ '{ "num1": 1, "num2": 2 }'
410
+ ```
411
+
412
+ This command would execute the state machine, and override the duration of the retry pause in states `SendRequest` and `ProcessData` to pause the execution for 1500 and 250 milliseconds, respectively. The retry in the `MapResponses` state wouldn't be paused at all, since the override value is set to 0.
413
+
365
414
  ### Passing a custom Context Object
366
415
 
367
416
  If the JSONPaths in your definition reference the Context Object, you can provide a mock Context Object by passing either the `--context` or the `--context-file` option. For example, given the following definition:
package/bin/CLI.cjs CHANGED
@@ -38,7 +38,7 @@ var import_readline = __toESM(require("readline"), 1);
38
38
  var import_commander = require("commander");
39
39
 
40
40
  // package.json
41
- var version = "1.3.0";
41
+ var version = "2.0.0";
42
42
 
43
43
  // src/cli/ArgumentParsers.ts
44
44
  var import_fs = require("fs");
@@ -111,6 +111,15 @@ function parseOverrideWaitOption(value, previous = {}) {
111
111
  previous[waitStateName] = Number(duration);
112
112
  return previous;
113
113
  }
114
+ function parseOverrideRetryOption(value, previous = {}) {
115
+ const [stateName, duration] = value.split(":");
116
+ if (!isNaN(duration)) {
117
+ previous[stateName] = Number(duration);
118
+ } else {
119
+ previous[stateName] = duration.split(",").map(Number);
120
+ }
121
+ return previous;
122
+ }
114
123
  function parseContextOption(command, context) {
115
124
  const jsonOrError = tryJSONParse(context);
116
125
  if (jsonOrError instanceof Error) {
@@ -167,7 +176,8 @@ async function commandAction(inputs, options, command) {
167
176
  const { result } = stateMachine.run(input, {
168
177
  overrides: {
169
178
  taskResourceLocalHandlers: options.overrideTask,
170
- waitTimeOverrides: options.overrideWait
179
+ waitTimeOverrides: options.overrideWait,
180
+ retryIntervalOverrides: options.overrideRetry
171
181
  },
172
182
  context: options.context ?? options.contextFile
173
183
  });
@@ -207,7 +217,7 @@ function makeProgram() {
207
217
  const command = new import_commander.Command();
208
218
  command.name("local-sfn").description(
209
219
  `Execute an Amazon States Language state machine with the given inputs.
210
- The result of each execution will be output in a new line and in the same order as its corresponding input.`
220
+ The result of each execution will be printed in a new line and in the same order as its corresponding input.`
211
221
  ).helpOption("-h, --help", "Print help for command and exit.").configureHelp({ helpWidth: 80 }).addHelpText(
212
222
  "after",
213
223
  `
@@ -234,6 +244,11 @@ Example calls:
234
244
  "-w, --override-wait <mapping>",
235
245
  "Override a Wait state to pause for the specified amount of milliseconds, instead of pausing for the duration specified in the state definition. The mapping value has to be provided in the format [WaitStateToOverride]:[number]."
236
246
  ).argParser(parseOverrideWaitOption)
247
+ ).addOption(
248
+ new import_commander.Option(
249
+ "-r, --override-retry <mapping>",
250
+ "Override a 'Retry' field to pause for the specified amount of milliseconds, instead of pausing for the duration specified by the retry policy. The mapping value has to be provided in the format [NameOfStateWithRetryField]:[number]."
251
+ ).argParser(parseOverrideRetryOption)
237
252
  ).addOption(
238
253
  new import_commander.Option(
239
254
  "--context <json>",