We have some EC2 instances running NGINX that will be accessed via a loadbalancer that can be reached via www.example.com. The loadbalancer redirects the traffic to the appropriate EC2 servers. This works fine, but sometimes we want to bypass the loadbalancer (to save money and increase data throughput). We connect on ip12-23-34-45.ec2.aws.amazon.com (example) and retrieve the information directly.
This works fine, but now we started to migrate to SSL for all our services. We have a domain certificate for the example.com domain and it works fine if we connect throught the load-balancer. When we connect to the EC2 servers directly, then it doesn't work because we present a certificate for our domain instead of the Amazon domain.
We can control the hostname where we want to redirect to, so I could choose to redirect to ec2.example.com instead of ec2.aws.amazon.com. So instead of redirecting to ip12-23-34-45.ec2.aws.amazon.com we would redirect to ip12-23-34-45.ec2.example.com. This presents the example.com certificate which should be fine.
The problem is that these hostnames cannot be resolved. Our servers are created dynamically and changing the Route53 DNS to modify the aliases over and over again seems a bit cumbersome. I would rather create a DNS rule in Route53 to map everything to .ec2.example.com to .ec2.aws.amazon.com.
Is it possible to create a rule that maps an entire subdomain to another subdomain in Route53? Or is there an other solution that we could use to bypass the load-balancer and still use SSL?