CloudFront can be configured to failover when receiving a specific code response from an origin location. This can help ensure that CloudFront sends requests to a different origin when the initial one becomes unreachable. This requires at least two origins to be configured as a part of an origin group. For more information, see the AWS documentation.
In AWS console -
In Terraform -