Skip to content

Commit e660890

Browse files
committed
aws sdk failure report lists the integration error name
1 parent 889c8c5 commit e660890

File tree

6 files changed

+181
-8
lines changed

6 files changed

+181
-8
lines changed

localstack-core/localstack/services/stepfunctions/asl/component/state/state_execution/state_task/service/state_task_service_aws_sdk.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@
55

66
from localstack.aws.api.stepfunctions import HistoryEventType, TaskFailedEventDetails
77
from localstack.aws.protocol.service_router import get_service_catalog
8+
from localstack.services.stepfunctions.asl.component.common.error_name.error_name import ErrorName
89
from localstack.services.stepfunctions.asl.component.common.error_name.failure_event import (
910
FailureEvent,
1011
)
11-
from localstack.services.stepfunctions.asl.component.common.error_name.states_error_name import (
12-
StatesErrorName,
13-
)
14-
from localstack.services.stepfunctions.asl.component.common.error_name.states_error_name_type import (
15-
StatesErrorNameType,
16-
)
1712
from localstack.services.stepfunctions.asl.component.state.state_execution.state_task.credentials import (
1813
StateCredentials,
1914
)
@@ -90,7 +85,7 @@ def _normalise_exception_name(norm_service_name: str, ex: Exception) -> str:
9085
def _get_task_failure_event(self, env: Environment, error: str, cause: str) -> FailureEvent:
9186
return FailureEvent(
9287
env=env,
93-
error_name=StatesErrorName(typ=StatesErrorNameType.StatesTaskFailed),
88+
error_name=ErrorName(error_name=error),
9489
event_type=HistoryEventType.TaskFailed,
9590
event_details=EventDetails(
9691
taskFailedEventDetails=TaskFailedEventDetails(

tests/aws/services/stepfunctions/templates/errorhandling/error_handling_templates.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77

88

99
class ErrorHandlingTemplate(TemplateLoader):
10-
# State Machines.
1110
AWS_SDK_TASK_FAILED_S3_LIST_OBJECTS: Final[str] = os.path.join(
1211
_THIS_FOLDER, "statemachines/aws_sdk_task_error_s3_list_objects.json5"
1312
)
1413

14+
AWS_SDK_TASK_FAILED_S3_NO_SUCH_KEY: Final[str] = os.path.join(
15+
_THIS_FOLDER, "statemachines/aws_sdk_task_error_s3_no_such_key.json5"
16+
)
17+
1518
AWS_SDK_TASK_FAILED_SECRETSMANAGER_CREATE_SECRET: Final[str] = os.path.join(
1619
_THIS_FOLDER, "statemachines/aws_sdk_task_error_secretsmanager_crate_secret.json5"
1720
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"QueryLanguage": "JSONata",
3+
"StartAt": "StartState",
4+
"States": {
5+
"StartState": {
6+
"Type": "Task",
7+
"Resource": "arn:aws:states:::aws-sdk:s3:getObject",
8+
"Arguments": {
9+
"Bucket": "{% $states.input.Bucket %}",
10+
"Key": "no_such_key.json"
11+
},
12+
"Catch": [
13+
{
14+
"ErrorEquals": [
15+
"S3.NoSuchKeyException"
16+
],
17+
"Output": "{% $states.errorOutput %}",
18+
"Next": "NoSuchKeyState"
19+
}
20+
],
21+
"Next": "TerminalState"
22+
},
23+
"TerminalState": {
24+
"Type": "Succeed"
25+
},
26+
"NoSuchKeyState": {
27+
"Type": "Fail"
28+
}
29+
}
30+
}

tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,29 @@ def test_no_such_bucket(
4949
exec_input,
5050
)
5151

52+
@markers.aws.validated
53+
def test_s3_no_such_key(
54+
self,
55+
aws_client,
56+
s3_create_bucket,
57+
create_state_machine_iam_role,
58+
create_state_machine,
59+
sfn_snapshot,
60+
):
61+
bucket_name = s3_create_bucket()
62+
sfn_snapshot.add_transformer(RegexTransformer(bucket_name, "bucket-name"))
63+
template = EHT.load_sfn_template(EHT.AWS_SDK_TASK_FAILED_S3_NO_SUCH_KEY)
64+
definition = json.dumps(template)
65+
exec_input = json.dumps({"Bucket": bucket_name})
66+
create_and_record_execution(
67+
aws_client,
68+
create_state_machine_iam_role,
69+
create_state_machine,
70+
sfn_snapshot,
71+
definition,
72+
exec_input,
73+
)
74+
5275
@pytest.mark.skipif(
5376
condition=not is_aws_cloud(),
5477
reason="No parameters validation for dynamodb api calls being returned.",

tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.snapshot.json

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,5 +520,124 @@
520520
}
521521
}
522522
}
523+
},
524+
"tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.py::TestAwsSdk::test_s3_no_such_key": {
525+
"recorded-date": "22-01-2025, 13:27:57",
526+
"recorded-content": {
527+
"get_execution_history": {
528+
"events": [
529+
{
530+
"executionStartedEventDetails": {
531+
"input": {
532+
"Bucket": "bucket-name"
533+
},
534+
"inputDetails": {
535+
"truncated": false
536+
},
537+
"roleArn": "snf_role_arn"
538+
},
539+
"id": 1,
540+
"previousEventId": 0,
541+
"timestamp": "timestamp",
542+
"type": "ExecutionStarted"
543+
},
544+
{
545+
"id": 2,
546+
"previousEventId": 0,
547+
"stateEnteredEventDetails": {
548+
"input": {
549+
"Bucket": "bucket-name"
550+
},
551+
"inputDetails": {
552+
"truncated": false
553+
},
554+
"name": "StartState"
555+
},
556+
"timestamp": "timestamp",
557+
"type": "TaskStateEntered"
558+
},
559+
{
560+
"id": 3,
561+
"previousEventId": 2,
562+
"taskScheduledEventDetails": {
563+
"parameters": {
564+
"Bucket": "bucket-name",
565+
"Key": "no_such_key.json"
566+
},
567+
"region": "<region>",
568+
"resource": "getObject",
569+
"resourceType": "aws-sdk:s3"
570+
},
571+
"timestamp": "timestamp",
572+
"type": "TaskScheduled"
573+
},
574+
{
575+
"id": 4,
576+
"previousEventId": 3,
577+
"taskStartedEventDetails": {
578+
"resource": "getObject",
579+
"resourceType": "aws-sdk:s3"
580+
},
581+
"timestamp": "timestamp",
582+
"type": "TaskStarted"
583+
},
584+
{
585+
"id": 5,
586+
"previousEventId": 4,
587+
"taskFailedEventDetails": {
588+
"cause": "The specified key does not exist. (Service: S3, Status Code: 404, Request ID: <request_id>, Extended Request ID: <extended_request_id>)",
589+
"error": "S3.NoSuchKeyException",
590+
"resource": "getObject",
591+
"resourceType": "aws-sdk:s3"
592+
},
593+
"timestamp": "timestamp",
594+
"type": "TaskFailed"
595+
},
596+
{
597+
"id": 6,
598+
"previousEventId": 5,
599+
"stateExitedEventDetails": {
600+
"name": "StartState",
601+
"output": {
602+
"Error": "S3.NoSuchKeyException",
603+
"Cause": "The specified key does not exist. (Service: S3, Status Code: 404, Request ID: <request_id>, Extended Request ID: <extended_request_id>)"
604+
},
605+
"outputDetails": {
606+
"truncated": false
607+
}
608+
},
609+
"timestamp": "timestamp",
610+
"type": "TaskStateExited"
611+
},
612+
{
613+
"id": 7,
614+
"previousEventId": 6,
615+
"stateEnteredEventDetails": {
616+
"input": {
617+
"Error": "S3.NoSuchKeyException",
618+
"Cause": "The specified key does not exist. (Service: S3, Status Code: 404, Request ID: <request_id>, Extended Request ID: <extended_request_id>)"
619+
},
620+
"inputDetails": {
621+
"truncated": false
622+
},
623+
"name": "NoSuchKeyState"
624+
},
625+
"timestamp": "timestamp",
626+
"type": "FailStateEntered"
627+
},
628+
{
629+
"executionFailedEventDetails": {},
630+
"id": 8,
631+
"previousEventId": 7,
632+
"timestamp": "timestamp",
633+
"type": "ExecutionFailed"
634+
}
635+
],
636+
"ResponseMetadata": {
637+
"HTTPHeaders": {},
638+
"HTTPStatusCode": 200
639+
}
640+
}
641+
}
523642
}
524643
}

tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.validation.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
},
1111
"tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.py::TestAwsSdk::test_no_such_bucket": {
1212
"last_validated_date": "2023-06-22T11:26:06+00:00"
13+
},
14+
"tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.py::TestAwsSdk::test_s3_no_such_key": {
15+
"last_validated_date": "2025-01-22T13:27:57+00:00"
1316
}
1417
}

0 commit comments

Comments
 (0)