Search code examples
amazon-ec2amazon-ecssubnetaws-security-group

A Timeout error occurs when EC2 and ECS using the same security group communicate


I'm having trouble communicating with EC2 and ECS.

When I send a request to ECS from EC2 that has the same security group as ECS, I get a Timeout error. However, the request can be received from ECS from outside.

Security group A allows all its own traffic.

EC2 Instance

  • private subnet A
  • security group A

ECS Load Balancer(internet facing)

  • public subnet A
  • security group A (for internal communication)
  • security group B (for external communication)

ECS Container

  • private subnets A and B
  • security group A

Solution

  • When you send traffic to a public facing load balancer it exits the VPC and comes back in. When the traffic exits the VPC it is no longer associated to a security group. Thus the security group no longer sees the traffic as coming from "itself" and it blocks the request.