Connection between fargate driver and ECS task is failing

Replace this template with your information

Describe your question in as much detail as possible:

When trigger a CI job, in ‘Autoscaling GitLab CI on AWS Fargate’ setup, it throws the below error.

ERRO[2021-02-01T10:23:46Z] Application execution failed PID=17244 error=“executing the script on the remote host: executing script on container with IP “3.89.131.50”: connecting to server: connecting to server “3.89.131.50:22” as user “root”: dial tcp 3.89.131.50:22: connect: connection timed out”

3.89.131.50 is container IP. I am sure this is related to the security group on /etc/gitlab-runner/fargate.toml configuration. Can someone explain what is the exact purpose of the security group in the below config.
LogLevel = “info”
LogFormat = “text”

[Fargate]
Cluster = “test-cluster”
Region = “us-east-2”
Subnet = “subnet-xxxxxx”
SecurityGroup = “sg-xxxxxxxxxxxxx”
TaskDefinition = “test-task:1”
EnablePublicIP = true

[TaskMetadata]
Directory = “/opt/gitlab-runner/metadata”

[SSH]
Username = “root”
Port = 22

Did you manage to solve your issue? Seeing the same problem

For me, the issue was that I had both the runner and the runner instance configured to run in private subnets. I had security groups setup to allow incoming ssh traffic from the runner agent security group to the runner instance security group, the latter of which was listed in the fargate.toml file. Using a public IP for the runner broke that, so I simply changed EnablePublicIP to false. The runner agent was then able to connect to the fargate runner instance.