In simple terms, the firewall is a component that is responsible for monitoring and controlling the incoming and outgoing traffic depending on the rules configured.
If we look into a cloud environment, such as AWS, they provide firewall functionality through a security group, which is attached to each EC2 instance and through NACL, which is attached to an entire subnet.