Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SFN] Catch and Retry With State.Runtime error literals #10687

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class ErrorHandlingTemplate(TemplateLoader):
_THIS_FOLDER, "statemachines/aws_service_sqs_send_msg_catch_token_failure.json5"
)

RUNTIME_ERROR_HANDLING: Final[str] = os.path.join(
_THIS_FOLDER, "statemachines/runtime_error_handling.json5"
)

# Lambda Functions.
LAMBDA_FUNC_LARGE_OUTPUT_STRING: Final[str] = os.path.join(
_THIS_FOLDER, "lambdafunctions/large_output_string.py"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"Comment": "RUNTIME_ERROR_HANDLING",
"StartAt": "ActivityTaskWithRuntimeCatch",
"States": {
"ActivityTaskWithRuntimeCatch": {
"Type": "Task",
"Resource": "_tbd_", // Resource field to be replaced dynamically.
"Catch": [
{
"ErrorEquals": [
"CustomErrorName", "States.Runtime"
],
"ResultPath": "$.RuntimeError",
"Next": "RuntimeErrorHandler"
},
{
"ErrorEquals": [
"States.ALL"
],
"ResultPath": "$.StatesAllError",
"Next": "StatesAllHandler"
}
],
"Retry": [
{
"ErrorEquals": [
"States.Runtime"
],
"IntervalSeconds": 1,
"MaxAttempts": 1,
"BackoffRate": 1.0,
}
],
"End": true
},
"RuntimeErrorHandler": {
"Type": "Pass",
"End": true
},
"StatesAllHandler": {
"Type": "Pass",
"End": true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,38 @@ def test_no_such_bucket(
exec_input,
)

@markers.aws.validated
def test_runtime_error_handling(
self,
aws_client,
create_iam_role_for_sfn,
create_state_machine,
create_activity,
sfn_snapshot,
):
activity_name = f"activity-{short_uid()}"
create_activity_output = create_activity(name=activity_name)
activity_arn = create_activity_output["activityArn"]
sfn_snapshot.add_transformer(RegexTransformer(activity_arn, "activity_arn"))
sfn_snapshot.add_transformer(RegexTransformer(activity_name, "activity_name"))
sfn_snapshot.match("create_activity_output", create_activity_output)

aws_client.stepfunctions.delete_activity(activityArn=activity_arn)

template = EHT.load_sfn_template(EHT.RUNTIME_ERROR_HANDLING)
template["States"]["ActivityTaskWithRuntimeCatch"]["Resource"] = activity_arn
definition = json.dumps(template)

exec_input = json.dumps({"Value1": "HelloWorld"})
create_and_record_execution(
aws_client.stepfunctions,
create_iam_role_for_sfn,
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,66 @@
}
}
}
},
"tests/aws/services/stepfunctions/v2/error_handling/test_aws_sdk.py::TestAwsSdk::test_runtime_error_handling": {
"recorded-date": "18-04-2024, 09:37:24",
"recorded-content": {
"create_activity_output": {
"activityArn": "activity_arn",
"creationDate": "datetime",
"ResponseMetadata": {
"HTTPHeaders": {},
"HTTPStatusCode": 200
}
},
"get_execution_history": {
"events": [
{
"executionStartedEventDetails": {
"input": {
"Value1": "HelloWorld"
},
"inputDetails": {
"truncated": false
},
"roleArn": "snf_role_arn"
},
"id": 1,
"previousEventId": 0,
"timestamp": "timestamp",
"type": "ExecutionStarted"
},
{
"id": 2,
"previousEventId": 0,
"stateEnteredEventDetails": {
"input": {
"Value1": "HelloWorld"
},
"inputDetails": {
"truncated": false
},
"name": "ActivityTaskWithRuntimeCatch"
},
"timestamp": "timestamp",
"type": "TaskStateEntered"
},
{
"executionFailedEventDetails": {
"cause": "An error occurred while executing the state 'ActivityTaskWithRuntimeCatch' (entered at the event id #2). The activity activity_arn does not exist.",
"error": "States.Runtime"
},
"id": 3,
"previousEventId": 2,
"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_runtime_error_handling": {
"last_validated_date": "2024-04-18T09:37:24+00:00"
}
}