You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[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
+
3
14
## Spec features
4
15
5
16
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](
88
99
-[x] Predefined error codes
89
100
-[x] Retry/Catch
90
101
91
-
### No support
102
+
### Not supported
92
103
93
104
- States
94
105
- Task
@@ -112,9 +123,47 @@ The following features all come from the [Amazon States Language specification](
112
123
113
124
The following features are not defined in the specification, but they have been added for convenience.
114
125
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.
0 commit comments