Skip to content

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

fix(ecs): preserve omitted optional task-definition fields (#1896)

Adrian-Ryan Acala0d6c665450c8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cfa6ea17..091e504c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,8 @@ Versioning follows [Semantic Versioning](https://semver.org/).
- **IoT — `DescribeEventConfigurations` and `UpdateEventConfigurations`** — both answered `Unsupported IoT path`; they now store the registry event switches per account and region, every type starting disabled, an update changing only the types it names, and `creationDate` / `lastModifiedDate` set from the first update on, as on AWS. Contributed by @iot-rocket.
### Fixed
+
+- **ECS — optional task-definition fields stay omitted** — registering an EC2 task definition without task-level `cpu`, `memory`, or `requiresCompatibilities` no longer invents `256`, `512`, or `["EC2"]` in register, describe, and deregister responses. Explicitly supplied values remain in the definition.
- **Cognito — `USER_SRP_AUTH` checks the password** — `PASSWORD_VERIFIER` answered random `SALT` and `SRP_B` values and accepted any response, so a wrong password, a missing `TIMESTAMP` or a disabled or unconfirmed user all got tokens. The challenge now carries SRP-6a parameters with a stable salt per user, and the response is refused with `NotAuthorizedException` unless its signature proves the stored password. `TIMESTAMP` must read `EEE MMM d HH:mm:ss z yyyy` with `UTC` or `GMT` as the zone, the signature is computed over its canonical form, `PASSWORD_CLAIM_SIGNATURE` must be base64, and a temporary password leads to `NEW_PASSWORD_REQUIRED`. A client without `ALLOW_USER_SRP_AUTH`, an unknown user under `LEGACY`, a disabled and an unconfirmed user are refused at `InitiateAuth`. The built-in `PASSWORD_VERIFIER` step of `CUSTOM_WITH_SRP` gets the same check. Contributed by @iot-rocket.
- **Cognito — refresh tokens are checked against the pool and client** — `REFRESH_TOKEN_AUTH` (`InitiateAuth`, `AdminInitiateAuth`) and `GetTokensFromRefreshToken` issued tokens for the first user in the pool when the refresh token was malformed, from another pool or of a deleted user, and accepted a token issued to another client; they now answer `NotAuthorizedException` with the message AWS gives for each case, and the refresh token from a SAML or OIDC federated sign-in now refreshes the federated user's session. Contributed by @iot-rocket.
- **CloudFormation — `AWS::S3Tables::TableBucket` and `AWS::S3Tables::Table` update in place** — a stack update re-ran the create, which reset the bucket's `createdAt` and rebuilt the table with a new `createdAt` and its initial metadata location, dropping committed metadata; a maintenance setting or tag change now keeps both, and a create-only table change under an unchanged name fails with the conflict AWS reports. Contributed by @iot-rocket.
diff --git a/ministack/services/ecs.py b/ministack/services/ecs.py
index 8cdcfad0..5a5533e7 100644
--- a/ministack/services/ecs.py
+++ b/ministack/services/ecs.py
@@ -642,9 +642,6 @@ def _register_task_definition(data):
"volumes": data.get("volumes", []),
"placementConstraints": data.get("placementConstraints", []),
"networkMode": network_mode,
- "requiresCompatibilities": compat,
- "cpu": data.get("cpu", "256"),
- "memory": data.get("memory", "512"),
"executionRoleArn": data.get("executionRoleArn", ""),
"taskRoleArn": data.get("taskRoleArn", ""),
"pidMode": data.get("pidMode", ""),
@@ -656,6 +653,9 @@ def _register_task_definition(data):
"registeredBy": f"arn:aws:iam::{get_account_id()}:root",
"compatibilities": compat + (["EC2"] if "FARGATE" in compat and "EC2" not in compat else []),
}
+ for field in ("requiresCompatibilities", "cpu", "memory"):
+ if field in data:
+ td[field] = data[field]
_task_defs[td_key] = td
req_tags = data.get("tags", [])
diff --git a/tests/test_ecs.py b/tests/test_ecs.py
index fe9711d0..734e8c73 100644
--- a/tests/test_ecs.py
+++ b/tests/test_ecs.py
@@ -74,6 +74,66 @@ def test_ecs_task_def(ecs):
assert resp["taskDefinition"]["family"] == "test-task"
assert resp["taskDefinition"]["revision"] == 1
[email protected]("cpu", [None, "512"])
[email protected]("memory", [None, "1024"])
[email protected]("requires_compatibilities", [None, ["EC2"]])
+def test_ecs_task_definition_optional_fields_readback(
+ ecs, cpu, memory, requires_compatibilities,
+):
+ # AWS RegisterTaskDefinition documents optional EC2 sizing and omission of
+ # unspecified requiresCompatibilities. Its register/describe/deregister
+ # examples omit task-level sizing when only container resources are given.
+ optional_fields = {
+ field: value for field, value in {
+ "cpu": cpu,
+ "memory": memory,
+ "requiresCompatibilities": requires_compatibilities,
+ }.items() if value is not None
+ }
+ registered = ecs.register_task_definition(
+ family=f"optional-fields-{_uuid_mod.uuid4().hex[:8]}",
+ containerDefinitions=[{
+ "name": "web", "image": "nginx:alpine", "cpu": 128, "memory": 256,
+ }],
+ **optional_fields,
+ )["taskDefinition"]
+ arn = registered["taskDefinitionArn"]
+ described = ecs.describe_task_definition(taskDefinition=arn)["taskDefinition"]
+ deregistered = ecs.deregister_task_definition(taskDefinition=arn)["taskDefinition"]
+
+ for td in (registered, described, deregistered):
+ for field in ("cpu", "memory", "requiresCompatibilities"):
+ if field in optional_fields:
+ assert td[field] == optional_fields[field]
+ else:
+ assert field not in td
+ assert td["containerDefinitions"][0]["cpu"] == 128
+ assert td["containerDefinitions"][0]["memory"] == 256
+ assert td["networkMode"] == "bridge"
+ assert registered["status"] == described["status"] == "ACTIVE"
+ assert deregistered["status"] == "INACTIVE"
+
+
+def test_ecs_task_definition_explicit_fargate_sizing_readback(ecs):
+ registered = ecs.register_task_definition(
+ family=f"explicit-fargate-{_uuid_mod.uuid4().hex[:8]}",
+ containerDefinitions=[{"name": "web", "image": "nginx:alpine"}],
+ networkMode="awsvpc",
+ requiresCompatibilities=["FARGATE"],
+ cpu="512",
+ memory="1024",
+ )["taskDefinition"]
+ arn = registered["taskDefinitionArn"]
+ described = ecs.describe_task_definition(taskDefinition=arn)["taskDefinition"]
+ deregistered = ecs.deregister_task_definition(taskDefinition=arn)["taskDefinition"]
+
+ for td in (registered, described, deregistered):
+ assert td["cpu"] == "512"
+ assert td["memory"] == "1024"
+ assert td["requiresCompatibilities"] == ["FARGATE"]
+ assert td["networkMode"] == "awsvpc"
+
+
def test_ecs_list_task_defs(ecs):
resp = ecs.list_task_definitions(familyPrefix="test-task")
assert len(resp["taskDefinitionArns"]) >= 1