Repository: getmoto/moto

Issue:
Missing launchType attribute in ECS run_task() and start_task()
Is it expected behavior that Moto ECS ignores the launch type (`FARGATE` and `EC2`) of tasks? When I start a task with either `run_task()` or `start_task()` I expect the `launchType` attribute in the response, but it is missing. The same happens when I query the description of the task.

## How to reproduce

```python
import warnings

warnings.filterwarnings(action="ignore", category=DeprecationWarning, module=r"boto")
warnings.filterwarnings(action="ignore", category=DeprecationWarning, module=r"moto")

import os
from dataclasses import dataclass
from typing import Type
import json

import boto3
from moto import mock_ecs, mock_ec2
from moto.ec2 import utils as ec2_utils
import pytest

@dataclass
class Boto:
    client: "typing.Any"
    resource: "typing.Any"


@pytest.fixture(scope="function")
def aws_credentials() -> object:
    os.environ["AWS_ACCESS_KEY_ID"] = "testing"
    os.environ["AWS_SECRET_ACCESS_KEY"] = "testing"
    os.environ["AWS_SECURITY_TOKEN"] = "testing"
    os.environ["AWS_SESSION_TOKEN"] = "testing"


@pytest.fixture(scope="function")
def ecs(aws_credentials) -> Type[Boto]:
    with mock_ecs():
        yield Boto(
            client=boto3.client("ecs", region_name="us-east-1"),
            resource=None
        )  


@pytest.fixture(scope="function")
def ec2(aws_credentials) -> Type[Boto]:
    with mock_ec2():
        yield Boto(
            client=boto3.client("ec2", region_name="us-east-1"),
            resource=boto3.resource("ec2", region_name="us-east-1")
        )  

def test_get_task_arns_with_run_task(fetcher, ecs, ec2):
    cluster_name = "test_ecs_cluster"

    response = ecs.client.create_cluster(clusterName=cluster_name)
    cluster_arn = response["cluster"]["clusterArn"]

    test_instances = ec2.resource.create_instances(
        ImageId="ami-bb9a6bc2", MinCount=3, MaxCount=3
    )

    for test_instance in test_instances:
        instance_id_document = json.dumps(
            ec2_utils.generate_instance_identity_document(test_instance)
        )
        _ = ecs.client.register_container_instance(
            cluster=cluster_name, instanceIdentityDocument=instance_id_document
        )

    _ = ecs.client.register_task_definition(
        family="test_ecs_task",
        containerDefinitions=[
            {
                "name": "hello_world",
                "image": "docker/hello-world:latest",
                "cpu": 1024,
                "memory": 400,
                "essential": True,
                "logConfiguration": {"logDriver": "json-file"},
            }
        ],
    )

    response = ecs.client.run_task(
        cluster=cluster_name,
        overrides={},
        taskDefinition="test_ecs_task",
        count=2,
        launchType="EC2",
        startedBy="moto",
    )
    # toolbox.pstruct(response, "run_task")

    assert len(response["tasks"]) == 2
    assert "launchType" in response["tasks"][0].keys()
    assert "launchType" in response["tasks"][1].keys()

    # task_arns = fetcher.get_task_arns(cluster_arn=cluster_arn)
    # assert len(task_arns) == 2
    # assert response["tasks"][0]["taskArn"] in task_arns
    # assert response["tasks"][1]["taskArn"] in task_arns
```

Here is the response:

```
{
  'tasks': [
    {
      'clusterArn': 'arn:aws:ecs:us-east-1:012345678910:cluster/test_ecs_cluster',
      'containerInstanceArn':
        'arn:aws:ecs:us-east-1:012345678910:container-instance/009ed692-3711-'
        '40b9-8f62-03b99ed149ac',
      'containers': [],
      'desiredStatus': 'RUNNING',
      'lastStatus': 'RUNNING',
      'overrides': {},
      'startedBy': 'moto',
      'stoppedReason': '',
      'taskArn':
        'arn:aws:ecs:us-east-1:012345678910:task/8c203f08-29be-4693-81a3-'
        '0adbef728a17',
      'taskDefinitionArn': 'arn:aws:ecs:us-east-1:012345678910:task-definition/test_ecs_task:1'
    },
    {
      'clusterArn': 'arn:aws:ecs:us-east-1:012345678910:cluster/test_ecs_cluster',
      'containerInstanceArn':
        'arn:aws:ecs:us-east-1:012345678910:container-instance/009ed692-3711-'
        '40b9-8f62-03b99ed149ac',
      'containers': [],
      'desiredStatus': 'RUNNING',
      'lastStatus': 'RUNNING',
      'overrides': {},
      'startedBy': 'moto',
      'stoppedReason': '',
      'taskArn':
        'arn:aws:ecs:us-east-1:012345678910:task/ebd38f0c-f691-4d63-8784-'
        '453a99f2c240',
      'taskDefinitionArn': 'arn:aws:ecs:us-east-1:012345678910:task-definition/test_ecs_task:1'
    }
  ],
  'failures': [],
  'ResponseMetadata': {
    'HTTPStatusCode': 200,
    'HTTPHeaders': {'server': 'amazon.com'},
    'RetryAttempts': 0
  }
}
```


Discussion:
Hi @trallnag, thanks for raising this. The `launchType`-parameter is not supported yet - will mark this as an enhancement.



Resolving patch:
diff --git a/moto/ecs/models.py b/moto/ecs/models.py
--- a/moto/ecs/models.py
+++ b/moto/ecs/models.py
@@ -289,6 +289,7 @@ def __init__(
         container_instance_arn,
         resource_requirements,
         backend,
+        launch_type="",
         overrides=None,
         started_by="",
         tags=None,
@@ -304,6 +305,7 @@ def __init__(
         self.containers = []
         self.started_by = started_by
         self.tags = tags or []
+        self.launch_type = launch_type
         self.stopped_reason = ""
         self.resource_requirements = resource_requirements
         self.region_name = cluster.region_name
@@ -887,7 +889,14 @@ def deregister_task_definition(self, task_definition_str):
             raise TaskDefinitionNotFoundException
 
     def run_task(
-        self, cluster_str, task_definition_str, count, overrides, started_by, tags
+        self,
+        cluster_str,
+        task_definition_str,
+        count,
+        overrides,
+        started_by,
+        tags,
+        launch_type,
     ):
         cluster = self._get_cluster(cluster_str)
 
@@ -930,6 +939,7 @@ def run_task(
                         overrides=overrides or {},
                         started_by=started_by or "",
                         tags=tags or [],
+                        launch_type=launch_type or "",
                     )
                     self.update_container_instance_resources(
                         container_instance, resource_requirements
diff --git a/moto/ecs/responses.py b/moto/ecs/responses.py
--- a/moto/ecs/responses.py
+++ b/moto/ecs/responses.py
@@ -118,8 +118,15 @@ def run_task(self):
         count = self._get_int_param("count")
         started_by = self._get_param("startedBy")
         tags = self._get_param("tags")
+        launch_type = self._get_param("launchType")
         tasks = self.ecs_backend.run_task(
-            cluster_str, task_definition_str, count, overrides, started_by, tags
+            cluster_str,
+            task_definition_str,
+            count,
+            overrides,
+            started_by,
+            tags,
+            launch_type,
         )
         return json.dumps(
             {"tasks": [task.response_object for task in tasks], "failures": []}


Test patch:
diff --git a/tests/test_ecs/test_ecs_boto3.py b/tests/test_ecs/test_ecs_boto3.py
--- a/tests/test_ecs/test_ecs_boto3.py
+++ b/tests/test_ecs/test_ecs_boto3.py
@@ -1611,7 +1611,7 @@ def test_run_task_default_cluster():
         ec2_utils.generate_instance_identity_document(test_instance)
     )
 
-    response = client.register_container_instance(
+    client.register_container_instance(
         cluster=test_cluster_name, instanceIdentityDocument=instance_id_document
     )
 
@@ -1639,6 +1639,7 @@ def test_run_task_default_cluster():
         startedBy="moto",
     )
     len(response["tasks"]).should.equal(2)
+    response["tasks"][0].should.have.key("launchType").equals("FARGATE")
     response["tasks"][0]["taskArn"].should.match(
         "arn:aws:ecs:us-east-1:{}:task/[a-z0-9-]+$".format(ACCOUNT_ID)
     )
@@ -1744,7 +1745,7 @@ def test_start_task():
         ec2_utils.generate_instance_identity_document(test_instance)
     )
 
-    response = client.register_container_instance(
+    client.register_container_instance(
         cluster=test_cluster_name, instanceIdentityDocument=instance_id_document
     )
 
@@ -1913,7 +1914,7 @@ def test_describe_tasks():
         ec2_utils.generate_instance_identity_document(test_instance)
     )
 
-    response = client.register_container_instance(
+    client.register_container_instance(
         cluster=test_cluster_name, instanceIdentityDocument=instance_id_document
     )