testState method
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:
- A state's input and output processing data flow
- An Amazon Web Services service integration request and response
- An HTTP Task request and response
TestState 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 IAM
permissions to test a state.
The TestState API can run for up to five minutes. If the
execution of a state exceeds this duration, it fails with the
States.Timeout error.
TestState only supports the following when a mock is
specified: Activity
tasks, .sync or .waitForTaskToken service
integration patterns, Parallel,
or Map
states.
May throw InvalidArn.
May throw InvalidDefinition.
May throw InvalidExecutionInput.
May throw ValidationException.
Parameter definition :
The Amazon
States Language (ASL) definition of the state or state machine.
Parameter context :
A JSON string representing a valid Context object for the state under
test. This field may only be specified if a mock is specified in the same
request.
Parameter input :
A string that contains the JSON input data for the state.
Parameter inspectionLevel :
Determines the values to return when a state is tested. You can specify
one of the following types:
-
INFO: Shows the final state output. By default, Step Functions setsinspectionLeveltoINFOif you don't specify a level. -
DEBUG: Shows the final state output along with the input and output data processing result. -
TRACE: Shows the HTTP request and response for an HTTP Task. This level also shows the final state output along with the input and output data processing result.
Parameter mock :
Defines a mocked result or error for the state under test.
A mock can only be specified for Task, Map, or Parallel states. If it is specified for another state type, an exception will be thrown.
Parameter revealSecrets :
Specifies whether or not to include secret information in the test result.
For HTTP Tasks, a secret includes the data that an EventBridge connection
adds to modify the HTTP request headers, query parameters, and body. Step
Functions doesn't omit any information included in the state definition or
the HTTP response.
If you set revealSecrets to true, you must make
sure that the IAM user that calls the TestState API has
permission for the states:RevealSecrets action. For an
example of IAM policy that sets the states:RevealSecrets
permission, see IAM
permissions to test a state. Without this permission, Step Functions
throws an access denied error.
By default, revealSecrets is set to false.
Parameter roleArn :
The Amazon Resource Name (ARN) of the execution role with the required IAM
permissions for the state.
Parameter stateConfiguration :
Contains configurations for the state under test.
Parameter stateName :
Denotes the particular state within a state machine definition to be
tested. If this field is specified, the definition must
contain a fully-formed state machine definition.
Parameter variables :
JSON object literal that sets variables used in the state under test.
Object keys are the variable names and values are the variable values.
Implementation
Future<TestStateOutput> testState({
required String definition,
String? context,
String? input,
InspectionLevel? inspectionLevel,
MockInput? mock,
bool? revealSecrets,
String? roleArn,
TestStateConfiguration? stateConfiguration,
String? stateName,
String? variables,
}) async {
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.0',
'X-Amz-Target': 'AWSStepFunctions.TestState'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'definition': definition,
if (context != null) 'context': context,
if (input != null) 'input': input,
if (inspectionLevel != null) 'inspectionLevel': inspectionLevel.value,
if (mock != null) 'mock': mock,
if (revealSecrets != null) 'revealSecrets': revealSecrets,
if (roleArn != null) 'roleArn': roleArn,
if (stateConfiguration != null)
'stateConfiguration': stateConfiguration,
if (stateName != null) 'stateName': stateName,
if (variables != null) 'variables': variables,
},
);
return TestStateOutput.fromJson(jsonResponse.body);
}