Scenario 1:
I have created the following resources in the order:
The problem I face in this case is, an EC2 gets launched by ASG and that doesn't connect to ECS because ECS_CLUSTER value is different from the actual cluster name. This feels obvious because ASG is launched before provider is added to cluster.
Scenario 2:
The service cannot launch because of an error: "No Container Instances were found in your cluster"
Scenario 2 confuses me - It isn't clear if ECS Scaling Policy would create the very first instance too or not?
Some solutions propose to keep the min capacity as 1, so that it works. But if I do that, I end up into Scenario 1, where the first EC2 instance can't register with ECS.
You have to use user_data
in your Launch Configuration or Template to correctly setup the instances for ECS. This includes providing a claster name as explained in AWS docs:
#!/bin/bash
cat <<'EOF' >> /etc/ecs/ecs.config
ECS_CLUSTER=your_cluster_name
EOF