To achieve high availability (HA) and enable traffic failover between two public subnets hosting EC2 instances with HA, you can utilize an Application Load Balancer (ALB).
Start by creating a target group and registering both EC2 instances (one in each subnet) as targets.
Next, configure an ALB to distribute incoming traffic across these targets. The ALB operates across multiple Availability Zones, ensuring failover by directing traffic to the healthy instance in the event of failure in one subnet. Additionally, configure health checks in the target group to monitor the EC2 instances’ availability and functionality, allowing the ALB to dynamically route traffic to the active instance. This setup ensures continuous traffic flow and enhances application reliability during subnet or instance failures.
these links have all the informations you need:
https://aws.amazon.com/elasticloadbalancing/ https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html