This template configures an S3 bucket as a static website with a routing rule that redirects requests to an EC2 instance when an HTTP 404 error occurs.

CloudFormation Template