Security groups in AWS are stateful. This means that if inbound traffic is allowed, the response traffic is automatically allowed back out, even if there is no explicit outbound rule.
By default, security groups allow all outbound traffic. However, if you remove all outbound rules, no outbound traffic is allowed.
The web server security group should allow inbound HTTP from anywhere and outbound MySQL traffic to the database security group. The database security group should allow inbound MySQL traffic only from the web server security group. This limits exposure and follows the principle of least privilege.
Security groups are stateful, so existing connections remain active even if the inbound rule is removed. However, new inbound connections will be blocked.
Limiting inbound traffic to only the previous tier's security group reduces exposure and follows the principle of least privilege, minimizing the attack surface.