Currently, we have 1 CloudFront & WAF service running in AWS that allows for one of the URL i.e. https://prod.contoso.com (out of 3) to connect with the EC2 Instance.
However, not sure If I can use the same CloudFront & WAF services for other 2 Public URL?
Are all 3 sites run on the same server? If so, it could work, otherwise, you’d need to inject an ALB in between cloudfront and the ec2 instance to handle some of the existing logic that cloudfront can’t do alone.
If they’re all on the same server, Add the additional CNAMEs to your cloudfront distribution for stage and test and ensure they’re on your ACM cert as well. In IIS, have the different websites configured to listen on the appropriate host header for the different sites. Update your DNS records to point to the cloudfront distribution and In theory, that should be all that’s required to get it flow properly.
If you wanted to have them on different servers, you’d need to add an ALB into the mix and do host based routing rules to the different target groups for each of the instances. You could still do it all with the single cloudfront distribution, with the same changes applying above for the most part.
Yes that’ll work pretty much as described. The only clarification is that route 53 will sit a layer above cloudfront, as that’s what will be responsible for directing users to cloudfront.
In terms of internal user access, how do you plan on changing the flow to go straight to the ALB? Will you have an internal DNS pointing to the address of the load balancer or some other method?
Generally, each layer will need to be accessible by the upper layer there connecting to it. For example, cloudfront will need to be able to connect to your ELB over 80/443. Your ELB will need to connect to your EC2 instance over 80/443.
Let’s start with cloudfront to the ELB. Cloudfront requires that origins by publicly accessible to connect to them, so have you:
deployed your load balancer in public subnets, as an internet load balancer?
opened up the security group attached to the load balancer to 80/443 to the world (0.0.0.0/0)? This part is 100% required as you could potentially white list cloudfront address space, but opening it wide open is easier for troubleshooting purposes.
Now let’s move into the ELB to EC2 instance. The security group attached to your EC2 instances, are you allowing 80/443 to the load balancer? The easiest way to accomplish that is allowing the traffic from the security group of the ELB itself, but you could also optionally allow it to the entire subnet where the load balancers are deployed.
Once you confirm those 2 pieces, it should start flowing nicely. Based on your health checks failing, you’re definitely not allowing the ELB —> EC2 connection, but possibly more may be misconfigured as well.