Skip to content

test_state

test_state(
    definition: Definition,
    *,
    config_overrides: Optional[SFNClientConfig] = None,
    role_arn: Optional[Arn] = None,
    input: Optional[SensitiveData] = None,
    inspection_level: Optional[InspectionLevel] = None,
    reveal_secrets: Optional[RevealSecrets] = None,
    variables: Optional[SensitiveData] = None,
    state_name: Optional[TestStateStateName] = None,
    mock: Optional[MockInput] = None,
    context: Optional[SensitiveData] = None,
    state_configuration: Optional[TestStateConfiguration] = None,
) -> TestStateOutput

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:

You can call this API on only one state at a time. The states that you can test include the following:

The 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.

Parameters:

  • definition (Definition) –

    The Amazon States Language (ASL) definition of the state or state machine.

  • role_arn (Optional[Arn], default: None ) –

    The Amazon Resource Name (ARN) of the execution role with the required IAM permissions for the state.

  • input (Optional[SensitiveData], default: None ) –

    A string that contains the JSON input data for the state.

  • inspection_level (Optional[InspectionLevel], default: None ) –

    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 sets inspectionLevel to INFO if 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.

    Each of these levels also provide information about the status of the state execution and the next state to transition to.

  • reveal_secrets (Optional[RevealSecrets], default: None ) –

    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.

  • variables (Optional[SensitiveData], default: None ) –

    JSON object literal that sets variables used in the state under test. Object keys are the variable names and values are the variable values.

  • state_name (Optional[TestStateStateName], default: None ) –

    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.

  • mock (Optional[MockInput], default: None ) –

    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.

  • context (Optional[SensitiveData], default: None ) –

    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.

  • state_configuration (Optional[TestStateConfiguration], default: None ) –

    Contains configurations for the state under test.

Raises:

Source code in docs_src/capo_sfn/_services/sfn.py
def test_state(
    self,
    definition: "capo_sfn.types.definition.Definition",
    *,
    config_overrides: Optional[SFNClientConfig] = None,
    role_arn: Optional["capo_sfn.types.arn.Arn"] = None,
    input: Optional["capo_sfn.types.sensitive_data.SensitiveData"] = None,
    inspection_level: Optional[
        "capo_sfn.types.inspection_level.InspectionLevel"
    ] = None,
    reveal_secrets: Optional["capo_sfn.types.reveal_secrets.RevealSecrets"] = None,
    variables: Optional["capo_sfn.types.sensitive_data.SensitiveData"] = None,
    state_name: Optional[
        "capo_sfn.types.test_state_state_name.TestStateStateName"
    ] = None,
    mock: Optional["capo_sfn.types.mock_input.MockInput"] = None,
    context: Optional["capo_sfn.types.sensitive_data.SensitiveData"] = None,
    state_configuration: Optional[
        "capo_sfn.types.test_state_configuration.TestStateConfiguration"
    ] = None,
) -> "capo_sfn.types.test_state_output.TestStateOutput":
    """<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> <ul> <li> <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> </li> <li> <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> </li> <li> <p>An <a href="https://docs.aws.amazon.com/step-functions/latest/dg/call-https-apis.html">HTTP Task</a> request and response</p> </li> </ul> <p>You can call this API on only one state at a time. The states that you can test include the following:</p> <ul> <li> <p> <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> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-pass-state.html">Pass</a> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-wait-state.html">Wait</a> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-choice-state.html">Choice</a> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-succeed-state.html">Succeed</a> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-fail-state.html">Fail</a> </p> </li> </ul> <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> <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> <p> <code>TestState</code> only supports the following when a mock is specified: <a href="https://docs.aws.amazon.com/step-functions/latest/dg/concepts-activities.html">Activity tasks</a>, <code>.sync</code> or <code>.waitForTaskToken</code> <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>

    Args:
        definition: <p>The <a href="https://docs.aws.amazon.com/step-functions/latest/dg/concepts-amazon-states-language.html">Amazon States Language</a> (ASL) definition of the state or state machine.</p>
        role_arn: <p>The Amazon Resource Name (ARN) of the execution role with the required IAM permissions for the state.</p>
        input: <p>A string that contains the JSON input data for the state.</p>
        inspection_level: <p>Determines the values to return when a state is tested. You can specify one of the following types:</p> <ul> <li> <p> <code>INFO</code>: Shows the final state output. By default, Step Functions sets <code>inspectionLevel</code> to <code>INFO</code> if you don't specify a level.</p> </li> <li> <p> <code>DEBUG</code>: Shows the final state output along with the input and output data processing result.</p> </li> <li> <p> <code>TRACE</code>: 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.</p> </li> </ul> <p>Each of these levels also provide information about the status of the state execution and the next state to transition to.</p>
        reveal_secrets: <p>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.</p> <p>If you set <code>revealSecrets</code> to <code>true</code>, you must make sure that the IAM user that calls the <code>TestState</code> API has permission for the <code>states:RevealSecrets</code> action. For an example of IAM policy that sets the <code>states:RevealSecrets</code> permission, 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>. Without this permission, Step Functions throws an access denied error.</p> <p>By default, <code>revealSecrets</code> is set to <code>false</code>.</p>
        variables: <p>JSON object literal that sets variables used in the state under test. Object keys are the variable names and values are the variable values.</p>
        state_name: <p>Denotes the particular state within a state machine definition to be tested. If this field is specified, the <code>definition</code> must contain a fully-formed state machine definition.</p>
        mock: <p>Defines a mocked result or error for the state under test.</p> <p>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.</p>
        context: <p>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.</p>
        state_configuration: <p>Contains configurations for the state under test.</p>

    Raises:
        capo_sfn.errors.invalid_arn.InvalidArn: <p>The provided Amazon Resource Name (ARN) is not valid.</p>
        capo_sfn.errors.invalid_definition.InvalidDefinition: <p>The provided Amazon States Language definition is not valid.</p>
        capo_sfn.errors.invalid_execution_input.InvalidExecutionInput: <p>The provided JSON input data is not valid.</p>
        capo_sfn.errors.validation_exception.ValidationException: <p>The input does not satisfy the constraints specified by an Amazon Web Services service.</p>
        capo_sfn.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_sfn.types.test_state_input.TestStateInput]",
    ) -> OperationResponse["capo_sfn.types.test_state_output.TestStateOutput"]:
        import capo_sfn._operations.aws_step_functions.test_state

        output, http_response = (
            capo_sfn._operations.aws_step_functions.test_state.test_state(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_sfn.types.test_state_input.TestStateInput",
    ) -> dict[str, Any]:
        import capo_sfn.types.test_state_input

        return capo_sfn.types.test_state_input.redact_sensitive(input_)

    def _redact_output(
        output: "capo_sfn.types.test_state_output.TestStateOutput",
    ) -> dict[str, Any]:
        import capo_sfn.types.test_state_output

        return capo_sfn.types.test_state_output.redact_sensitive(output)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "TestState", redact_input=_redact_input, redact_output=_redact_output
        ),
    )
    input_: capo_sfn.types.test_state_input.TestStateInput = {
        "definition": definition
    }
    if role_arn is not None:
        input_["role_arn"] = role_arn
    if input is not None:
        input_["input"] = input
    if inspection_level is not None:
        input_["inspection_level"] = inspection_level
    if reveal_secrets is not None:
        input_["reveal_secrets"] = reveal_secrets
    if variables is not None:
        input_["variables"] = variables
    if state_name is not None:
        input_["state_name"] = state_name
    if mock is not None:
        input_["mock"] = mock
    if context is not None:
        input_["context"] = context
    if state_configuration is not None:
        input_["state_configuration"] = state_configuration

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output