Skip to content

Commit 71df280

Browse files
author
awstools
committed
feat(client-sfn): Adds new TestState operation which accepts the definition of a single state and executes it. You can test a state without creating a state machine or updating an existing state machine.
1 parent a78717e commit 71df280

File tree

10 files changed

+985
-14
lines changed

10 files changed

+985
-14
lines changed

clients/client-sfn/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,14 @@ TagResource
469469

470470
[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/sfn/command/TagResourceCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-sfn/Interface/TagResourceCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-sfn/Interface/TagResourceCommandOutput/)
471471

472+
</details>
473+
<details>
474+
<summary>
475+
TestState
476+
</summary>
477+
478+
[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/sfn/command/TestStateCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-sfn/Interface/TestStateCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-sfn/Interface/TestStateCommandOutput/)
479+
472480
</details>
473481
<details>
474482
<summary>

clients/client-sfn/src/SFN.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ import {
149149
StopExecutionCommandOutput,
150150
} from "./commands/StopExecutionCommand";
151151
import { TagResourceCommand, TagResourceCommandInput, TagResourceCommandOutput } from "./commands/TagResourceCommand";
152+
import { TestStateCommand, TestStateCommandInput, TestStateCommandOutput } from "./commands/TestStateCommand";
152153
import {
153154
UntagResourceCommand,
154155
UntagResourceCommandInput,
@@ -203,6 +204,7 @@ const commands = {
203204
StartSyncExecutionCommand,
204205
StopExecutionCommand,
205206
TagResourceCommand,
207+
TestStateCommand,
206208
UntagResourceCommand,
207209
UpdateMapRunCommand,
208210
UpdateStateMachineCommand,
@@ -692,6 +694,17 @@ export interface SFN {
692694
cb: (err: any, data?: TagResourceCommandOutput) => void
693695
): void;
694696

697+
/**
698+
* @see {@link TestStateCommand}
699+
*/
700+
testState(args: TestStateCommandInput, options?: __HttpHandlerOptions): Promise<TestStateCommandOutput>;
701+
testState(args: TestStateCommandInput, cb: (err: any, data?: TestStateCommandOutput) => void): void;
702+
testState(
703+
args: TestStateCommandInput,
704+
options: __HttpHandlerOptions,
705+
cb: (err: any, data?: TestStateCommandOutput) => void
706+
): void;
707+
695708
/**
696709
* @see {@link UntagResourceCommand}
697710
*/

clients/client-sfn/src/SFNClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ import { StartExecutionCommandInput, StartExecutionCommandOutput } from "./comma
114114
import { StartSyncExecutionCommandInput, StartSyncExecutionCommandOutput } from "./commands/StartSyncExecutionCommand";
115115
import { StopExecutionCommandInput, StopExecutionCommandOutput } from "./commands/StopExecutionCommand";
116116
import { TagResourceCommandInput, TagResourceCommandOutput } from "./commands/TagResourceCommand";
117+
import { TestStateCommandInput, TestStateCommandOutput } from "./commands/TestStateCommand";
117118
import { UntagResourceCommandInput, UntagResourceCommandOutput } from "./commands/UntagResourceCommand";
118119
import { UpdateMapRunCommandInput, UpdateMapRunCommandOutput } from "./commands/UpdateMapRunCommand";
119120
import {
@@ -167,6 +168,7 @@ export type ServiceInputTypes =
167168
| StartSyncExecutionCommandInput
168169
| StopExecutionCommandInput
169170
| TagResourceCommandInput
171+
| TestStateCommandInput
170172
| UntagResourceCommandInput
171173
| UpdateMapRunCommandInput
172174
| UpdateStateMachineAliasCommandInput
@@ -207,6 +209,7 @@ export type ServiceOutputTypes =
207209
| StartSyncExecutionCommandOutput
208210
| StopExecutionCommandOutput
209211
| TagResourceCommandOutput
212+
| TestStateCommandOutput
210213
| UntagResourceCommandOutput
211214
| UpdateMapRunCommandOutput
212215
| UpdateStateMachineAliasCommandOutput

clients/client-sfn/src/commands/RedriveExecutionCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface RedriveExecutionCommandOutput extends RedriveExecutionOutput, _
3939
* @public
4040
* <p>Restarts unsuccessful executions of Standard workflows that didn't complete successfully in the last 14 days. These include failed, aborted, or timed out executions. When you <a href="https://docs.aws.amazon.com/step-functions/latest/dg/redrive-executions.html">redrive</a> an execution, it continues the failed execution from the unsuccessful step and uses the same input. Step Functions preserves the results and execution history of the successful steps, and doesn't rerun these steps when you redrive an execution. Redriven executions use the same state machine definition and execution ARN as the original execution attempt.</p>
4141
* <p>For workflows that include an <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-map-state.html">Inline Map</a> or <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-parallel-state.html">Parallel</a> state, <code>RedriveExecution</code> API action reschedules and redrives only the iterations and branches that failed or aborted.</p>
42-
* <p>To redrive a workflow that includes a Distributed Map state with failed child workflow executions, you must redrive the <a href="https://docs.aws.amazon.com/step-functions/latest/dg/use-dist-map-orchestrate-large-scale-parallel-workloads.html#dist-map-orchestrate-parallel-workloads-key-terms">parent workflow</a>. The parent workflow redrives all the unsuccessful states, including Distributed Map.</p>
42+
* <p>To redrive a workflow that includes a Distributed Map state whose Map Run failed, you must redrive the <a href="https://docs.aws.amazon.com/step-functions/latest/dg/use-dist-map-orchestrate-large-scale-parallel-workloads.html#dist-map-orchestrate-parallel-workloads-key-terms">parent workflow</a>. The parent workflow redrives all the unsuccessful states, including a failed Map Run. If a Map Run was not started in the original execution attempt, the redriven parent workflow starts the Map Run.</p>
4343
* <note>
4444
* <p>This API action is not supported by <code>EXPRESS</code> state machines.</p>
4545
* <p>However, you can restart the unsuccessful executions of Express child workflows in a Distributed Map by redriving its Map Run. When you redrive a Map Run, the Express child workflows are rerun using the <a>StartExecution</a> API action. For more information, see <a href="https://docs.aws.amazon.com/step-functions/latest/dg/redrive-map-run.html">Redriving Map Runs</a>.</p>
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
// smithy-typescript generated code
2+
import { EndpointParameterInstructions, getEndpointPlugin } from "@smithy/middleware-endpoint";
3+
import { getSerdePlugin } from "@smithy/middleware-serde";
4+
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http";
5+
import { Command as $Command } from "@smithy/smithy-client";
6+
import {
7+
FinalizeHandlerArguments,
8+
Handler,
9+
HandlerExecutionContext,
10+
HttpHandlerOptions as __HttpHandlerOptions,
11+
MetadataBearer as __MetadataBearer,
12+
MiddlewareStack,
13+
SerdeContext as __SerdeContext,
14+
SMITHY_CONTEXT_KEY,
15+
} from "@smithy/types";
16+
17+
import {
18+
TestStateInput,
19+
TestStateInputFilterSensitiveLog,
20+
TestStateOutput,
21+
TestStateOutputFilterSensitiveLog,
22+
} from "../models/models_0";
23+
import { de_TestStateCommand, se_TestStateCommand } from "../protocols/Aws_json1_0";
24+
import { ServiceInputTypes, ServiceOutputTypes, SFNClientResolvedConfig } from "../SFNClient";
25+
26+
/**
27+
* @public
28+
*/
29+
export { __MetadataBearer, $Command };
30+
/**
31+
* @public
32+
*
33+
* The input for {@link TestStateCommand}.
34+
*/
35+
export interface TestStateCommandInput extends TestStateInput {}
36+
/**
37+
* @public
38+
*
39+
* The output of {@link TestStateCommand}.
40+
*/
41+
export interface TestStateCommandOutput extends TestStateOutput, __MetadataBearer {}
42+
43+
/**
44+
* @public
45+
* <p>Accepts the definition of a single state and executes it. You can test a state without creating a state machine or updating an existing state machine. Using this API, you can test the following:</p>
46+
* <ul>
47+
* <li>
48+
* <p>A state's <a href="https://docs.aws.amazon.com/step-functions/latest/dg/test-state-isolation.html#test-state-input-output-dataflow">input and output processing</a> data flow</p>
49+
* </li>
50+
* <li>
51+
* <p>An <a href="https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-services.html">Amazon Web Services service integration</a> request and response</p>
52+
* </li>
53+
* <li>
54+
* <p>An <a href="https://docs.aws.amazon.com/step-functions/latest/dg/connect-third-party-apis.html">HTTP Task</a> request and response</p>
55+
* </li>
56+
* </ul>
57+
* <p>You can call this API on only one state at a time. The states that you can test include the following:</p>
58+
* <ul>
59+
* <li>
60+
* <p>
61+
* <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-task-state.html#task-types">All Task types</a> except <a href="https://docs.aws.amazon.com/step-functions/latest/dg/concepts-activities.html">Activity</a>
62+
* </p>
63+
* </li>
64+
* <li>
65+
* <p>
66+
* <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-pass-state.html">Pass</a>
67+
* </p>
68+
* </li>
69+
* <li>
70+
* <p>
71+
* <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-wait-state.html">Wait</a>
72+
* </p>
73+
* </li>
74+
* <li>
75+
* <p>
76+
* <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-choice-state.html">Choice</a>
77+
* </p>
78+
* </li>
79+
* <li>
80+
* <p>
81+
* <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-succeed-state.html">Succeed</a>
82+
* </p>
83+
* </li>
84+
* <li>
85+
* <p>
86+
* <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-fail-state.html">Fail</a>
87+
* </p>
88+
* </li>
89+
* </ul>
90+
* <p>The <code>TestState</code> API assumes an IAM role which must contain the required IAM permissions for the resources your state is accessing. For information about the permissions a state might need, see <a href="https://docs.aws.amazon.com/step-functions/latest/dg/test-state-isolation.html#test-state-permissions">IAM permissions to test a state</a>.</p>
91+
* <p>The <code>TestState</code> API can run for up to five minutes. If the execution of a state exceeds this duration, it fails with the <code>States.Timeout</code> error.</p>
92+
* <p>
93+
* <code>TestState</code> doesn't support <a href="https://docs.aws.amazon.com/step-functions/latest/dg/concepts-activities.html">Activity tasks</a>, <code>.sync</code> or <code>.waitForTaskToken</code>
94+
* <a href="https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html">service integration patterns</a>, <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-parallel-state.html">Parallel</a>, or <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-map-state.html">Map</a> states.</p>
95+
* @example
96+
* Use a bare-bones client and the command you need to make an API call.
97+
* ```javascript
98+
* import { SFNClient, TestStateCommand } from "@aws-sdk/client-sfn"; // ES Modules import
99+
* // const { SFNClient, TestStateCommand } = require("@aws-sdk/client-sfn"); // CommonJS import
100+
* const client = new SFNClient(config);
101+
* const input = { // TestStateInput
102+
* definition: "STRING_VALUE", // required
103+
* roleArn: "STRING_VALUE", // required
104+
* input: "STRING_VALUE",
105+
* inspectionLevel: "INFO" || "DEBUG" || "TRACE",
106+
* revealSecrets: true || false,
107+
* };
108+
* const command = new TestStateCommand(input);
109+
* const response = await client.send(command);
110+
* // { // TestStateOutput
111+
* // output: "STRING_VALUE",
112+
* // error: "STRING_VALUE",
113+
* // cause: "STRING_VALUE",
114+
* // inspectionData: { // InspectionData
115+
* // input: "STRING_VALUE",
116+
* // afterInputPath: "STRING_VALUE",
117+
* // afterParameters: "STRING_VALUE",
118+
* // result: "STRING_VALUE",
119+
* // afterResultSelector: "STRING_VALUE",
120+
* // afterResultPath: "STRING_VALUE",
121+
* // request: { // InspectionDataRequest
122+
* // protocol: "STRING_VALUE",
123+
* // method: "STRING_VALUE",
124+
* // url: "STRING_VALUE",
125+
* // headers: "STRING_VALUE",
126+
* // body: "STRING_VALUE",
127+
* // },
128+
* // response: { // InspectionDataResponse
129+
* // protocol: "STRING_VALUE",
130+
* // statusCode: "STRING_VALUE",
131+
* // statusMessage: "STRING_VALUE",
132+
* // headers: "STRING_VALUE",
133+
* // body: "STRING_VALUE",
134+
* // },
135+
* // },
136+
* // nextState: "STRING_VALUE",
137+
* // status: "SUCCEEDED" || "FAILED" || "RETRIABLE" || "CAUGHT_ERROR",
138+
* // };
139+
*
140+
* ```
141+
*
142+
* @param TestStateCommandInput - {@link TestStateCommandInput}
143+
* @returns {@link TestStateCommandOutput}
144+
* @see {@link TestStateCommandInput} for command's `input` shape.
145+
* @see {@link TestStateCommandOutput} for command's `response` shape.
146+
* @see {@link SFNClientResolvedConfig | config} for SFNClient's `config` shape.
147+
*
148+
* @throws {@link InvalidArn} (client fault)
149+
* <p>The provided Amazon Resource Name (ARN) is not valid.</p>
150+
*
151+
* @throws {@link InvalidDefinition} (client fault)
152+
* <p>The provided Amazon States Language definition is not valid.</p>
153+
*
154+
* @throws {@link InvalidExecutionInput} (client fault)
155+
* <p>The provided JSON input data is not valid.</p>
156+
*
157+
* @throws {@link ValidationException} (client fault)
158+
* <p>The input does not satisfy the constraints specified by an Amazon Web Services service.</p>
159+
*
160+
* @throws {@link SFNServiceException}
161+
* <p>Base exception class for all service exceptions from SFN service.</p>
162+
*
163+
*/
164+
export class TestStateCommand extends $Command<TestStateCommandInput, TestStateCommandOutput, SFNClientResolvedConfig> {
165+
public static getEndpointParameterInstructions(): EndpointParameterInstructions {
166+
return {
167+
UseFIPS: { type: "builtInParams", name: "useFipsEndpoint" },
168+
Endpoint: { type: "builtInParams", name: "endpoint" },
169+
Region: { type: "builtInParams", name: "region" },
170+
UseDualStack: { type: "builtInParams", name: "useDualstackEndpoint" },
171+
};
172+
}
173+
174+
/**
175+
* @public
176+
*/
177+
constructor(readonly input: TestStateCommandInput) {
178+
super();
179+
}
180+
181+
/**
182+
* @internal
183+
*/
184+
resolveMiddleware(
185+
clientStack: MiddlewareStack<ServiceInputTypes, ServiceOutputTypes>,
186+
configuration: SFNClientResolvedConfig,
187+
options?: __HttpHandlerOptions
188+
): Handler<TestStateCommandInput, TestStateCommandOutput> {
189+
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));
190+
this.middlewareStack.use(getEndpointPlugin(configuration, TestStateCommand.getEndpointParameterInstructions()));
191+
192+
const stack = clientStack.concat(this.middlewareStack);
193+
194+
const { logger } = configuration;
195+
const clientName = "SFNClient";
196+
const commandName = "TestStateCommand";
197+
const handlerExecutionContext: HandlerExecutionContext = {
198+
logger,
199+
clientName,
200+
commandName,
201+
inputFilterSensitiveLog: TestStateInputFilterSensitiveLog,
202+
outputFilterSensitiveLog: TestStateOutputFilterSensitiveLog,
203+
[SMITHY_CONTEXT_KEY]: {
204+
service: "AWSStepFunctions",
205+
operation: "TestState",
206+
},
207+
};
208+
const { requestHandler } = configuration;
209+
return stack.resolve(
210+
(request: FinalizeHandlerArguments<any>) =>
211+
requestHandler.handle(request.request as __HttpRequest, options || {}),
212+
handlerExecutionContext
213+
);
214+
}
215+
216+
/**
217+
* @internal
218+
*/
219+
private serialize(input: TestStateCommandInput, context: __SerdeContext): Promise<__HttpRequest> {
220+
return se_TestStateCommand(input, context);
221+
}
222+
223+
/**
224+
* @internal
225+
*/
226+
private deserialize(output: __HttpResponse, context: __SerdeContext): Promise<TestStateCommandOutput> {
227+
return de_TestStateCommand(output, context);
228+
}
229+
}

clients/client-sfn/src/commands/UpdateStateMachineAliasCommand.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ export interface UpdateStateMachineAliasCommandOutput extends UpdateStateMachine
121121
* @throws {@link ResourceNotFound} (client fault)
122122
* <p>Could not find the referenced resource.</p>
123123
*
124+
* @throws {@link StateMachineDeleting} (client fault)
125+
* <p>The specified state machine is being deleted.</p>
126+
*
124127
* @throws {@link ValidationException} (client fault)
125128
* <p>The input does not satisfy the constraints specified by an Amazon Web Services service.</p>
126129
*

clients/client-sfn/src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export * from "./StartExecutionCommand";
3030
export * from "./StartSyncExecutionCommand";
3131
export * from "./StopExecutionCommand";
3232
export * from "./TagResourceCommand";
33+
export * from "./TestStateCommand";
3334
export * from "./UntagResourceCommand";
3435
export * from "./UpdateMapRunCommand";
3536
export * from "./UpdateStateMachineAliasCommand";

0 commit comments

Comments
 (0)