diff --git a/localstack-core/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/state_task_service_aws_sdk.py b/localstack-core/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/state_task_service_aws_sdk.py index 6593280901674..e4f7f031355d3 100644 --- a/localstack-core/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/state_task_service_aws_sdk.py +++ b/localstack-core/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/state_task_service_aws_sdk.py @@ -5,15 +5,10 @@ from localstack.aws.api.stepfunctions import HistoryEventType, TaskFailedEventDetails from localstack.aws.protocol.service_router import get_service_catalog +from localstack.services.stepfunctions.asl.component.common.error_name.error_name import ErrorName from localstack.services.stepfunctions.asl.component.common.error_name.failure_event import ( FailureEvent, ) -from localstack.services.stepfunctions.asl.component.common.error_name.states_error_name import ( - StatesErrorName, -) -from localstack.services.stepfunctions.asl.component.common.error_name.states_error_name_type import ( - StatesErrorNameType, -) from localstack.services.stepfunctions.asl.component.state.state_execution.state_task.credentials import ( StateCredentials, ) @@ -90,7 +85,7 @@ def _normalise_exception_name(norm_service_name: str, ex: Exception) -> str: def _get_task_failure_event(self, env: Environment, error: str, cause: str) -> FailureEvent: return FailureEvent( env=env, - error_name=StatesErrorName(typ=StatesErrorNameType.StatesTaskFailed), + error_name=ErrorName(error_name=error), event_type=HistoryEventType.TaskFailed, event_details=EventDetails( taskFailedEventDetails=TaskFailedEventDetails( diff --git a/tests/aws/services/stepfunctions/templates/errorhandling/error_handling_templates.py b/tests/aws/services/stepfunctions/templates/errorhandling/error_handling_templates.py index 881e5a37d7906..d7ef0a28d6839 100644 --- a/tests/aws/services/stepfunctions/templates/errorhandling/error_handling_templates.py +++ b/tests/aws/services/stepfunctions/templates/errorhandling/error_handling_templates.py @@ -7,11 +7,14 @@ class ErrorHandlingTemplate(TemplateLoader): - # State Machines. AWS_SDK_TASK_FAILED_S3_LIST_OBJECTS: Final[str] = os.path.join( _THIS_FOLDER, "statemachines/aws_sdk_task_error_s3_list_objects.json5" ) + AWS_SDK_TASK_FAILED_S3_NO_SUCH_KEY: Final[str] = os.path.join( + _THIS_FOLDER, "statemachines/aws_sdk_task_error_s3_no_such_key.json5" + ) + AWS_SDK_TASK_FAILED_SECRETSMANAGER_CREATE_SECRET: Final[str] = os.path.join( _THIS_FOLDER, "statemachines/aws_sdk_task_error_secretsmanager_crate_secret.json5" ) diff --git a/tests/aws/services/stepfunctions/templates/errorhandling/statemachines/aws_sdk_task_error_s3_no_such_key.json5 b/tests/aws/services/stepfunctions/templates/errorhandling/statemachines/aws_sdk_task_error_s3_no_such_key.json5 new file mode 100644 index 0000000000000..20123f91e9540 --- /dev/null +++ b/tests/aws/services/stepfunctions/templates/errorhandling/statemachines/aws_sdk_task_error_s3_no_such_key.json5 @@ -0,0 +1,30 @@ +{ + "QueryLanguage": "JSONata", + "StartAt": "StartState", + "States": { + "StartState": { + "Type": "Task", + "Resource": "arn:aws:states:::aws-sdk:s3:getObject", + "Arguments": { + "Bucket": "{% $states.input.Bucket %}", + "Key": "no_such_key.json" + }, + "Catch": [ + { + "ErrorEquals": [ + "S3.NoSuchKeyException" + ], + "Output": "{% $states.errorOutput %}", + "Next": "NoSuchKeyState" + } + ], + "Next": "TerminalState" + }, + "TerminalState": { + "Type": "Succeed" + }, + "NoSuchKeyState": { + "Type": "Fail" + } + } +} diff --git a/tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.py b/tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.py index 7cdc28dc6073f..2118440e7f338 100644 --- a/tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.py +++ b/tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.py @@ -49,6 +49,29 @@ def test_no_such_bucket( exec_input, ) + @markers.aws.validated + def test_s3_no_such_key( + self, + aws_client, + s3_create_bucket, + create_state_machine_iam_role, + create_state_machine, + sfn_snapshot, + ): + bucket_name = s3_create_bucket() + sfn_snapshot.add_transformer(RegexTransformer(bucket_name, "bucket-name")) + template = EHT.load_sfn_template(EHT.AWS_SDK_TASK_FAILED_S3_NO_SUCH_KEY) + definition = json.dumps(template) + exec_input = json.dumps({"Bucket": bucket_name}) + create_and_record_execution( + aws_client, + create_state_machine_iam_role, + create_state_machine, + sfn_snapshot, + definition, + exec_input, + ) + @pytest.mark.skipif( condition=not is_aws_cloud(), reason="No parameters validation for dynamodb api calls being returned.", diff --git a/tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.snapshot.json b/tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.snapshot.json index b3d0cd8ed607a..5c9c8a9492767 100644 --- a/tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.snapshot.json +++ b/tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.snapshot.json @@ -520,5 +520,124 @@ } } } + }, + "tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.py::TestAwsSdk::test_s3_no_such_key": { + "recorded-date": "22-01-2025, 13:27:57", + "recorded-content": { + "get_execution_history": { + "events": [ + { + "executionStartedEventDetails": { + "input": { + "Bucket": "bucket-name" + }, + "inputDetails": { + "truncated": false + }, + "roleArn": "snf_role_arn" + }, + "id": 1, + "previousEventId": 0, + "timestamp": "timestamp", + "type": "ExecutionStarted" + }, + { + "id": 2, + "previousEventId": 0, + "stateEnteredEventDetails": { + "input": { + "Bucket": "bucket-name" + }, + "inputDetails": { + "truncated": false + }, + "name": "StartState" + }, + "timestamp": "timestamp", + "type": "TaskStateEntered" + }, + { + "id": 3, + "previousEventId": 2, + "taskScheduledEventDetails": { + "parameters": { + "Bucket": "bucket-name", + "Key": "no_such_key.json" + }, + "region": "", + "resource": "getObject", + "resourceType": "aws-sdk:s3" + }, + "timestamp": "timestamp", + "type": "TaskScheduled" + }, + { + "id": 4, + "previousEventId": 3, + "taskStartedEventDetails": { + "resource": "getObject", + "resourceType": "aws-sdk:s3" + }, + "timestamp": "timestamp", + "type": "TaskStarted" + }, + { + "id": 5, + "previousEventId": 4, + "taskFailedEventDetails": { + "cause": "The specified key does not exist. (Service: S3, Status Code: 404, Request ID: , Extended Request ID: )", + "error": "S3.NoSuchKeyException", + "resource": "getObject", + "resourceType": "aws-sdk:s3" + }, + "timestamp": "timestamp", + "type": "TaskFailed" + }, + { + "id": 6, + "previousEventId": 5, + "stateExitedEventDetails": { + "name": "StartState", + "output": { + "Error": "S3.NoSuchKeyException", + "Cause": "The specified key does not exist. (Service: S3, Status Code: 404, Request ID: , Extended Request ID: )" + }, + "outputDetails": { + "truncated": false + } + }, + "timestamp": "timestamp", + "type": "TaskStateExited" + }, + { + "id": 7, + "previousEventId": 6, + "stateEnteredEventDetails": { + "input": { + "Error": "S3.NoSuchKeyException", + "Cause": "The specified key does not exist. (Service: S3, Status Code: 404, Request ID: , Extended Request ID: )" + }, + "inputDetails": { + "truncated": false + }, + "name": "NoSuchKeyState" + }, + "timestamp": "timestamp", + "type": "FailStateEntered" + }, + { + "executionFailedEventDetails": {}, + "id": 8, + "previousEventId": 7, + "timestamp": "timestamp", + "type": "ExecutionFailed" + } + ], + "ResponseMetadata": { + "HTTPHeaders": {}, + "HTTPStatusCode": 200 + } + } + } } } diff --git a/tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.validation.json b/tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.validation.json index 5f302b576ac2d..d6e69325c9cb1 100644 --- a/tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.validation.json +++ b/tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.validation.json @@ -10,5 +10,8 @@ }, "tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.py::TestAwsSdk::test_no_such_bucket": { "last_validated_date": "2023-06-22T11:26:06+00:00" + }, + "tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.py::TestAwsSdk::test_s3_no_such_key": { + "last_validated_date": "2025-01-22T13:27:57+00:00" } }