Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(stepfunctions): the first matching retrier decides (#2077)

Jeff Hellerc559fa4e24cc
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1aae7509..c16047e0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
- **IoT — `DescribeCertificate` reports `certificateMode`** — the field was missing from the description. It is now `SNI_ONLY` for a certificate registered with `RegisterCertificateWithoutCA` and `DEFAULT` for the others, as AWS reports it. Contributed by @iot-rocket.
### Fixed
+- **Step Functions — the first matching retrier decides** — a retrier that had used its `MaxAttempts` (or had `MaxAttempts: 0`) was skipped, so a later matching retrier such as `States.ALL` retried the error anyway. The first retrier whose `ErrorEquals` matches now decides: once it has used its attempts the state fails (or goes to its `Catch`), as the Developer Guide's error-handling examples describe.
- **S3 — cross-account replication** — `PutBucketReplication` dropped `Destination.Account` and `AccessControlTranslation`, and the replica write looked the destination bucket up only in the caller's account, so a destination owned by another account stamped every object `FAILED`. The destination is now found by its bucket name in any account and the replica (object, versions, tags, annotations, on-disk files) lands in the owner's scope. A cross-account destination requires its bucket policy to grant the rule's `Role` `s3:ReplicateObject`, plus `s3:ObjectOwnerOverrideToBucketOwner` when `AccessControlTranslation` is set and the destination is not `BucketOwnerEnforced`; otherwise the source reports `FAILED`. `PutBucketReplication` / `GetBucketReplication` round-trip `Filter` (`Prefix`, `Tag`, `And`), `Priority`, `DeleteMarkerReplication`, `Destination.Account` and `AccessControlTranslation`, and the destination-versioning check at configuration time sees buckets in any account. Contributed by @pingedbrain.
- **RDS Data API — MySQL `generatedFields`** — `ExecuteStatement` and `BatchExecuteStatement` always answered `generatedFields: []`, so an `INSERT` into an `AUTO_INCREMENT` table gave no way to read the new id. On the MySQL engines it now holds the id the server assigned (`[{"longValue": <id>}]`), or `[]` when none was assigned; `BatchExecuteStatement` reports it in each parameter set's update result. Aurora PostgreSQL still returns `[]`: the API reference says it does not support `generatedFields` and points to `RETURNING`.
- **SSM — `PutParameter` validates `Type`, reserved names and `Tags` with `Overwrite`** — three requests that AWS refuses were accepted. Creating a parameter without `Type` now fails with `ValidationException` ("A parameter type is required when you create a parameter."), and an overwrite without `Type` keeps the stored type instead of resetting it to `String`, so a `SecureString` no longer turns into plaintext. Names whose first characters (after an optional leading `/`) are `aws` or `ssm`, in any case, are refused: `/aws...` with `AccessDeniedException`, everything else with `ValidationException`, all HTTP 400. `Tags` together with `Overwrite=true` fails with `ValidationException` whether or not the parameter exists; an empty `Tags` list is accepted. Matches AWS observed in us-east-1 on 2026-10-06. Reported by @jin-gizmo.
diff --git a/ministack/services/stepfunctions.py b/ministack/services/stepfunctions.py
index a88187f4..c9e3ded2 100644
--- a/ministack/services/stepfunctions.py
+++ b/ministack/services/stepfunctions.py
@@ -3088,11 +3088,11 @@ def _error_matches(error_equals, error):
def _find_matching_retrier(retriers, error, retry_counts):
+ """The first retrier matching the error decides; once it has used its MaxAttempts there is no retry."""
for idx, retrier in enumerate(retriers):
- max_attempts = retrier.get("MaxAttempts", 3)
- if retry_counts.get(idx, 0) >= max_attempts:
- continue
if _error_matches(retrier.get("ErrorEquals", []), error):
+ if retry_counts.get(idx, 0) >= retrier.get("MaxAttempts", 3):
+ return None, -1
return retrier, idx
return None, -1
diff --git a/tests/test_stepfunctions.py b/tests/test_stepfunctions.py
index 00348f3d..36ee6aa2 100644
--- a/tests/test_stepfunctions.py
+++ b/tests/test_stepfunctions.py
@@ -3492,6 +3492,31 @@ def test_sfn_task_failed_does_not_match_states_timeout(sfn, sqs):
assert [e["type"] for e in events].count("TaskScheduled") == 1
+def test_sfn_exhausted_retrier_does_not_fall_through_to_a_later_one(sfn, lam):
+ """The first matching retrier decides: MaxAttempts 0 never retries, even with States.ALL after it."""
+ fn = f"sfn-first-retrier-{time.time_ns()}"
+ lam.create_function(
+ FunctionName=fn, Runtime="python3.12", Role=_LAMBDA_ROLE, Handler="index.handler",
+ Code={"ZipFile": _make_zip("def handler(e, c): raise Exception('no')\n")},
+ )
+ sm = sfn.create_state_machine(
+ name=fn, roleArn="arn:aws:iam::000000000000:role/R",
+ definition=json.dumps({"StartAt": "Call", "States": {
+ "Call": {"Type": "Task", "Resource": lam.get_function(FunctionName=fn)["Configuration"]["FunctionArn"],
+ "Retry": [{"ErrorEquals": ["States.TaskFailed"], "MaxAttempts": 0},
+ {"ErrorEquals": ["States.ALL"], "IntervalSeconds": 1, "MaxAttempts": 2}],
+ "Catch": [{"ErrorEquals": ["States.ALL"], "Next": "Caught"}], "End": True},
+ "Caught": {"Type": "Pass", "End": True},
+ }}),
+ )
+ ex = sfn.start_execution(stateMachineArn=sm["stateMachineArn"], input="{}")
+
+ desc = _wait_sfn(sfn, ex["executionArn"], timeout=30)
+ assert desc["status"] == "SUCCEEDED", desc.get("cause")
+ events = sfn.get_execution_history(executionArn=ex["executionArn"])["events"]
+ assert [e["type"] for e in events].count("TaskScheduled") == 1
+
+
_SFN_FAIL_BRANCH = {"StartAt": "F", "States": {"F": {"Type": "Fail", "Error": "MyErr", "Cause": "c"}}}