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.
References:
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/high_availability_origin_failover.html
In AWS console -
In Terraform -