Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
23 changes: 23 additions & 0 deletions tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<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: <request_id>, Extended 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: <request_id>, Extended 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: <request_id>, Extended 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
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Loading