We can see the options for AWS Fargate and EC2 Launch type while creating ECS cluster and also can see while creating Task Definition. So 2 places we are choosing these options. Since We have to choose Fargate method or EC2 Launch type while creating our task definition. So what is the difference between these two ? Why we need to opt the same for while creating cluster ?
When creating a cluster you are defining the ECS launch types that the cluster will support. And if you decide to support EC2 launch types when creating the cluster, that is the point where you would configure the cluster to be able to create EC2 instances. You define at the cluster level the EC2 image, EC2 auto-scaling group, etc.
On the task definition you are simply telling ECS that this specific task needs to run on Fargate, or it needs to run on EC2. You can't define EC2 instances that the task will run on, you are simply saying "I need this task to run on this type of execution environment". Since a cluster can possibly support both Fargate and EC2 launch types, you have to have that setting on the task so the cluster knows which launch type to use for that specific task.