Skip to content

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

fix(sfn): deep-convert ecs:runTask Parameters so ContainerOverrides reach the task (#886) (#887)

Lucase90f19b90d0c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index adb20501..29f6a8de 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,13 @@ Unreleased
- **IAM — `GenerateServiceLastAccessedDetails`, `GetServiceLastAccessedDetails`** — Access Advisor generate→get job handshake. Returns a UUID `JobId`. `GetServiceLastAccessedDetails` returns `JobStatus=COMPLETED` and an empty `ServicesLastAccessed` list (no CloudTrail data).
+---
+
+## [Unreleased]
+
+### Fixed
+- **Step Functions — `ecs:runTask` / `ecs:runTask.sync` no longer drop `ContainerOverrides`** — the Pascal→camelCase conversion at the SFN→ECS hand-off only covered top-level Parameters keys, so `Overrides.ContainerOverrides` (including resolved `"Value.$"` entries) stayed PascalCase and was silently ignored: the container ran with task-definition env only while the task launched and the `.sync` state succeeded. The conversion is now recursive; nested `NetworkConfiguration` is covered by the same pass. (#886)
+
---
## [1.3.61] — 2026-06-10
diff --git a/ministack/services/stepfunctions.py b/ministack/services/stepfunctions.py
index 6b985acb..e9df2a5e 100644
--- a/ministack/services/stepfunctions.py
+++ b/ministack/services/stepfunctions.py
@@ -3915,13 +3915,15 @@ def _poll_ecs_tasks(cluster, task_arns):
def _pascal_to_camel(d):
- """Convert top-level PascalCase keys to camelCase for ECS internals."""
+ """Recursively convert PascalCase keys to camelCase for ECS internals."""
+ if isinstance(d, list):
+ return [_pascal_to_camel(v) for v in d]
if not isinstance(d, dict):
return d
out = {}
for k, v in d.items():
new_key = k[0].lower() + k[1:] if k else k
- out[new_key] = v
+ out[new_key] = _pascal_to_camel(v)
return out
diff --git a/tests/test_stepfunctions.py b/tests/test_stepfunctions.py
index ffdec461..9d74d375 100644
--- a/tests/test_stepfunctions.py
+++ b/tests/test_stepfunctions.py
@@ -1799,6 +1799,81 @@ def test_sfn_integration_ecs_run_task_output_contains_status(sfn, ecs):
assert task_out["lastStatus"] == "RUNNING"
assert "failures" in output
+def test_sfn_integration_ecs_run_task_container_overrides_reach_the_task(sfn, ecs):
+ """PascalCase ContainerOverrides must survive the SFN->ECS hand-off instead of being silently dropped."""
+ ecs.create_cluster(clusterName="sfn-ecs-overrides")
+ ecs.register_task_definition(
+ family="sfn-overrides-task",
+ containerDefinitions=[
+ {
+ "name": "main",
+ "image": "alpine:latest",
+ "command": ["echo", "hi"],
+ "memory": 128,
+ "environment": [{"name": "FROM_TASKDEF", "value": "yes"}],
+ }
+ ],
+ )
+
+ definition = json.dumps(
+ {
+ "StartAt": "Run",
+ "States": {
+ "Run": {
+ "Type": "Task",
+ "Resource": "arn:aws:states:::ecs:runTask",
+ "Parameters": {
+ "Cluster": "sfn-ecs-overrides",
+ "TaskDefinition": "sfn-overrides-task",
+ "LaunchType": "FARGATE",
+ "Overrides": {
+ "ContainerOverrides": [
+ {
+ "Name": "main",
+ "Environment": [
+ {"Name": "FROM_OVERRIDES", "Value": "yes"},
+ {"Name": "RUN_ID", "Value.$": "$$.Execution.Name"},
+ ],
+ }
+ ]
+ },
+ },
+ "End": True,
+ },
+ },
+ }
+ )
+ sm = sfn.create_state_machine(
+ name="sfn-ecs-overrides",
+ definition=definition,
+ roleArn="arn:aws:iam::000000000000:role/R",
+ )
+ ex = sfn.start_execution(
+ stateMachineArn=sm["stateMachineArn"], name="overrides-exec-1", input="{}"
+ )
+
+ desc = _wait_sfn(sfn, ex["executionArn"])
+ assert desc["status"] == "SUCCEEDED"
+ output = json.loads(desc["output"])
+ task_out = output["tasks"][0]
+
+ env = {
+ e["name"]: e["value"]
+ for ov in task_out["overrides"]["containerOverrides"]
+ for e in ov["environment"]
+ }
+ assert env == {"FROM_OVERRIDES": "yes", "RUN_ID": "overrides-exec-1"}
+ assert task_out["overrides"]["containerOverrides"][0]["name"] == "main"
+
+ # boto3 parses DescribeTasks against the real ECS model (camelCase only)
+ described = ecs.describe_tasks(
+ cluster="sfn-ecs-overrides", tasks=[task_out["taskArn"]]
+ )
+ described_overrides = described["tasks"][0]["overrides"]["containerOverrides"]
+ assert described_overrides[0]["name"] == "main"
+ described_env = {e["name"]: e["value"] for e in described_overrides[0]["environment"]}
+ assert described_env == {"FROM_OVERRIDES": "yes", "RUN_ID": "overrides-exec-1"}
+
def test_sfn_integration_nested_start_execution_sync_returns_string_output(sfn):
"""states:startExecution.sync should return the child Output as a JSON string."""
unique = str(time.time_ns())