diff --git a/moto/ecs/models.py b/moto/ecs/models.py index 5689ccbdb19a..b05c3749f475 100644 --- a/moto/ecs/models.py +++ b/moto/ecs/models.py @@ -1138,6 +1138,14 @@ def register_task_definition( pid_mode: Optional[str] = None, ephemeral_storage: Optional[Dict[str, int]] = None, ) -> TaskDefinition: + + if requires_compatibilities and "FARGATE" in requires_compatibilities: + # TODO need more validation for Fargate + if pid_mode and pid_mode != "task": + raise EcsClientException( + f"Tasks using the Fargate launch type do not support pidMode '{pid_mode}'. The supported value for pidMode is 'task'." + ) + if family in self.task_definitions: last_id = self._get_last_task_definition_revision_id(family) revision = (last_id or 0) + 1 diff --git a/tests/test_ecs/test_ecs_boto3.py b/tests/test_ecs/test_ecs_boto3.py index 51b74be22d9e..912b7be5825b 100644 --- a/tests/test_ecs/test_ecs_boto3.py +++ b/tests/test_ecs/test_ecs_boto3.py @@ -293,6 +293,33 @@ def test_register_task_definition(): ) +@mock_ecs +def test_register_task_definition_fargate_with_pid_mode(): + client = boto3.client("ecs", region_name="us-east-1") + definition = dict( + family="test_ecs_task", + containerDefinitions=[ + {"name": "hello_world", "image": "hello-world:latest", "memory": 400} + ], + requiresCompatibilities=["FARGATE"], + pidMode="host", + networkMode="awsvpc", + cpu="256", + memory="512", + ) + + with pytest.raises(ClientError) as exc: + client.register_task_definition(**definition) + ex = exc.value + assert ex.operation_name == "RegisterTaskDefinition" + assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400 + assert ex.response["Error"]["Code"] == "ClientException" + assert ( + ex.response["Error"]["Message"] + == "Tasks using the Fargate launch type do not support pidMode 'host'. The supported value for pidMode is 'task'." + ) + + @mock_ecs def test_list_task_definitions(): client = boto3.client("ecs", region_name="us-east-1")