Skip to content

Commit d6a771b

Browse files
committed
Add a more in-depth description of the non-spec features
1 parent 1c149e7 commit d6a771b

File tree

3 files changed

+58
-7
lines changed

3 files changed

+58
-7
lines changed

docs/feature-support.md

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Feature support
22

3+
## Table of contents
4+
5+
- [Spec features](#spec-features)
6+
- [Fully supported](#fully-supported)
7+
- [Not supported](#not-supported)
8+
- [Non-spec features](#non-spec-features)
9+
- [Task resource override](#task-state-resource-override)
10+
- [Wait duration override](#wait-state-duration-override)
11+
- [Abort a running execution](#abort-a-running-execution)
12+
- [AWS config for Lambda functions](#providing-aws-credentials-and-region-to-execute-lambda-functions-specified-in-task-states)
13+
314
## Spec features
415

516
The following features all come from the [Amazon States Language specification](https://states-language.net/).
@@ -88,7 +99,7 @@ The following features all come from the [Amazon States Language specification](
8899
- [x] Predefined error codes
89100
- [x] Retry/Catch
90101

91-
### No support
102+
### Not supported
92103

93104
- States
94105
- Task
@@ -112,9 +123,47 @@ The following features all come from the [Amazon States Language specification](
112123

113124
The following features are not defined in the specification, but they have been added for convenience.
114125

115-
- [x] Override `Task` state resource with a local function handler ([example](/examples/task-state-local-override.js))
116-
- [x] Override `Wait` state duration ([example](/examples/wait-state-local-override.js))
117-
- [x] Abort a running execution ([example](/examples/abort-execution.js))
118-
- [x] Providing AWS credentials to execute Lambda functions specified in `Task` states:
119-
- [x] Specifying access key ID and secret access key ([example](/examples/aws-credentials-access-keys.js))
120-
- [x] Specifying a Cognito Identity Pool ([example](/examples/aws-credentials-cognito.js))
126+
### `Task` state resource override
127+
128+
`aws-local-stepfunctions` has the ability to invoke Lambda functions specified in the `Resource` field of `Task` states, provided that you have the necessary AWS credentials. No other service integrations are currently available.
129+
130+
However, if you want to be able to run a state machine completely locally (no matter the type of `Resource` specified) you can specify a local function to be called in place of the resource. This is accomplished through the `overrides.taskResourceLocalHandlers` option of the [`StateMachine.run`](/README.md#statemachineruninput-options) method. This option expects an object that maps state names to an overriding local function.
131+
132+
The overriding function will receive the processed input of its `Task` state as the first argument. The return value of said function will be the result of the state (but not its output, which as defined in the spec, depends on further processing done by the `ResultSelector`, `ResultPath` and `OutputPath` fields).
133+
134+
Effectively, task resource overrides allow `aws-local-stepfunctions` to execute state machines without calls to any AWS service, if you override all of the `Task` states in the state machine definition.
135+
136+
An example usage of this feature can be found [here](/examples/task-state-local-override.js).
137+
138+
### `Wait` state duration override
139+
140+
As defined by the spec, `Wait` states in `aws-local-stepfunction` will pause the state machine execution until the specified `Seconds` have elapsed or the specified `Timestamp` has been reached.
141+
142+
Nonetheless, if you want to override the duration of the wait period of a `Wait` state, you can do so by specifying the `overrides.waitTimeOverrides` option of the [`StateMachine.run`](/README.md#statemachineruninput-options) method. This option expects an object that maps state names to numbers, where the number represents the amount of milliseconds that the overridden `Wait` state will pause the execution for. Note that you may pass `0` for the number value, which effectively means that the overridden `Wait` state will not pause the execution at all.
143+
144+
An example usage of this feature can be found [here](/examples/wait-state-local-override.js).
145+
146+
### Abort a running execution
147+
148+
If for some reason you need to abort an execution in progress, you can do so by calling the `abort` method that is part of the value returned by the `StateMachine.run` method.
149+
150+
By default, aborting an execution will throw an error of type `ExecutionAbortedError`, which you can catch and compare against using `instanceof`. A demonstration of this behavior can be found in this [example](/examples/abort-execution.js).
151+
152+
If instead you prefer to abort an execution without throwing an error, you can pass the `noThrowOnAbort` option to the `StateMachine.run` method. When this option is `true`, aborting an execution will simply return `null` as result. Likewise, an example demonstrating this behavior can be found [here](/examples/abort-execution-without-throwing.js).
153+
154+
### Providing AWS credentials and region to execute Lambda functions specified in `Task` states
155+
156+
_NOTE: If you have [overridden](#task-state-resource-override) all `Task` states in your state machine with local functions, you don't need to specify any AWS credentials or region._
157+
158+
When using `aws-local-stepfunctions` on Node, you don't need to specify AWS credentials explicitly, as those will be automatically loaded from the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` [environment variables](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/loading-node-credentials-environment.html) or from the [shared credentials file](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/loading-node-credentials-shared.html), as described in the [AWS JavaScript SDK docs](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html).
159+
160+
Similarly, you don't need to specify the AWS region, as it will also be automatically loaded, in this case from the `AWS_REGION` environment variable or from the shared config file, as described in the [SDK docs](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-region.html).
161+
162+
However, when using `aws-local-stepfunctions` in the browser you must provide AWS credentials, otherwise the `aws-local-stepfunctions` will not be able to invoke the Lambda functions and the execution will fail.
163+
164+
To provide credentials and region, specify the `stateMachineOptions.awsConfig` option in the `StateMachine` [constructor](/README.md#constructor-new-statemachinedefinition-statemachineoptions). You can set two types of credentials:
165+
166+
1. [Access Keys](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html): Access Key ID and Secret Access Key ([example](/examples/aws-credentials-access-keys.js)).
167+
2. [Cognito Identity Pool](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-identity.html): The ID of a Cognito Identity Pool ([example](/examples/aws-credentials-cognito.js)).
168+
169+
Make sure that the IAM user/role associated with the access keys or Cognito Identity Pool have the necessary policies to be able to invoke the Lambda functions referenced in your state machine definition.

examples/task-state-local-override.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const execution = stateMachine.run(myInput, {
2525
// by specifying the Task state name as the key and the local function as value, as in the example below:
2626
taskResourceLocalHandlers: {
2727
// Call the `addNumbersLocal` function instead of invoking the Lambda function specified for the `AddNumbers` state.
28+
// Note that the key is the name of the `Task` state that we want to override.
2829
AddNumbers: addNumbersLocal,
2930
},
3031
},

examples/wait-state-local-override.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const execution = stateMachine.run(myInput, {
1818
// Property `waitTimeOverrides` lets you override any number of Wait states,
1919
// by specifying the Wait state name as the key and the duration override as value (represented in milliseconds):
2020
waitTimeOverrides: {
21+
// Note that the key is the name of the `Wait` state that we want to override.
2122
Wait10Seconds: 500, // wait for 500 milliseconds instead of the 10 seconds specified in the `Wait10Seconds` state
2223
},
2324
},

0 commit comments

Comments
 (0)