Allow ECS Fargate task access to EC2 instance using Security Group ID instead of IP

I am trying to allow an ECS task on one security group to access an EC2 instance on another security group so that I can access a mongo database hosted on the EC2 instance. Both security groups are under the same VPC.

I have added an inbound rule to the security group of the EC2 instance and set the source to the security group of the ECS fargate task like so: Security Group inbound rule

However when I then try that, this does not allow access. Only when I use the ECS task’s public or private IP does it actually allow it through. I have confirmed that the ECS task is indeed on the security group that is being allowed access to the EC2 instance. Is it possible to just allow a security group access? I want any ECS task I start to be allowed access without me needing to manually add the IP to the rules if possible.

Leave a Comment