You have a web application deployed to AWS Elastic Beanstalk. You even own a cool domain bought for a super special price. It seems like you have all you need to make it working together but for some reasons the domain registrant does not allow you to point the domain to AWS EBS URL. They want you to use IP address instead.
Prerequisites
- Deployed, up and running Elastic Beanstalk application. You should have a URL under which the application is available.
It means that if you enter the URL from the above page (in my case it is http://myapp-env.somepartofurl123.eu-central-1.elasticbeanstalk.com) in a web browser, you will see your application. - A registered domain for example example.com. I will describe here a little more difficult case - when the domain is registered through a different company not Amazon.
Goal
URLs like http://myapp-env.somepartofurl123.eu-central-1.elasticbeanstalk.com are hard to remember and are far from being attractive. That is why I would like users of my application to access the application through my domain which is something like http://example.com. If that is your case too, the article will guide you through the process.
Generally, a request for example.com should go to AWS Route 53 which will resolve the name to a specific Elastic IP address that is assigned to EC2. EC2 hosts the Elastic Beanstalk application.
Configure Route 53
A good first step is to configure Route 53 for your application and domain.
- Log into AWS Console.
- Locate Route 53 and open it.
- In Route 53 choose DNS management and click Get started.
- Once you are in DNS management, click Create Hosted Zone.
- On the Create Hosted Zone form type in the domain name (in my example example.com), comment is optional, type should be Public Hosted Zone. Then click Create.
- Once the hosted zone is created it automatically gets two records: NS and SOA. Copy the value for NS (the grey area on the below screenshot). It should contain a list of servers with a dot after each one - you will need that list later but without the ending dots.
- Find EC2 in AWS Console. You will need to find an IP address assigned to EC2 server which hosts Elastic Beanstalk that manages the application.
- When you are in EC2 Dashboard, click the link with Running Instances (in my case there is one).
- You will see a list of instances. Select the one you want to associate with the domain and copy Elastic IP from the details section. This is an IP address that you can refer to when connecting to your application. If you need to create a cluster, Elastic IP can be switched between EC2 instances so it is useful to use that one.
- Now, you can go back to Route 53 Hosted zones. You can click Create Record Set to create the third entry. Set the following field values:
- Name - you can leave it empty as it will default to the hosted zone name which is your domain name at the same time.
- Type - A - IPv4 address.
- Alias - No.
- Value - Elastic IP - the value you copied EC2 properties.
- After these operations you should see three records in the hosted zone: A, NS and SOA.
Change name servers for the domain
Your domain (e.g. example.com) still has the original name servers in the domain registrant records - the company where you registered the domain. You have to change them to the AWS ones.
To do that, go to the client panel of the company where you registered a domain and you should find a place where name servers are associated with the domain. Change them to the ones listed as a value of the NS record in Route 53. Remember to remove the tailing dots after each server. Unfortunately, the procedure may slightly differ between different registrants.
That is all needed to point the domain traffic to Elastic Beanstalk application. Now, if you go to example.com in a web browser, most probably you will see no difference. It will take a while (up to 48 hours) for DNS server to refresh the domain information. After 2 days (but probably sooner) you should be able to access your application through your domain name.
Read more
Deployment of two applications on one AWS Elastic Beanstalk container