How to point domain to AWS Elastic Beanstalk

route53You 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

  1. Deployed, up and running Elastic Beanstalk application. You should have a URL under which the application is available.
    elastic beanstalk2
    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.

  2. 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.

network diagram

 

 

Configure Route 53

A good first step is to configure Route 53 for your application and domain.

  1. Log into AWS Console.

  2. Locate Route 53 and open it.
    find Route 53
  3. In Route 53 choose DNS management and click Get started.
    choose DNS management
  4. Once you are in DNS management, click Create Hosted Zone.
    03 hosted zones
  5. 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.
    04 create hosted zone
  6. 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.
    05 created record sets
  7. 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.
    find EC2
  8. When you are in EC2 Dashboard, click the link with Running Instances (in my case there is one).
    07 EC2 dashboard
  9. 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.
    running instances get IP
  10. 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.
    Then click Create.
    create record in hosted zones
  11. 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

GitLab CI/CD deployment to AWS Elastic Beanstalk