Creating a custom domain name for AWS Elastic Beanstalk application
Tags: aws, route53, elasticbeanstalk, django
Published: 2024-04-01 03:38:47

Amazon Route 53 is a highly available and scalable Domain Name System (DNS) service. Besides traffic management, Route 53 provides various features such as domain name registration, DNS routing policies and health checks.

![Amazon Route 53](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7g47htvslz2a1cz7u8ra.png)

## Registering a domain

1. In the [Route 53 console](https://us-east-1.console.aws.amazon.com/route53/domains/home?region=us-east-1#/), select **Registered domains** in the navigation pane and click **Register domains**.
![Register domains](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yo49hrjrqe75s20xlpde.png)

2. Enter a desired domain name and click **Search**. From the list of the available domains, choose one and click **Select**.
![Search for domains](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pgablb8fupagd8bcpjsd.png)

3. Click **Proceed to checkout**.
![Selected domains](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tiy75yjtxe74ibj18nq4.png)

4. Select the duration and/or (un)check the Auto-renew option, and click **Next**.
![Pricing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sxwcustppdnpjtwk4sjw.png)

5. Enter the contact information and click **Next**.
![Contact information](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1vpc5rknypwnqp0ia9fq.png)![Contact information](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2b7r382havcxfr6eab3e.png)

6. Review the information, accept the terms and conditions, and click **Submit**.
![Review and submit](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hrnc6z8ofqglwoeg81n2.png)![Review and submit](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hiwz60b1eirepb31il2i.png)

> **Note**: The registration can take up to 15 minutes. You may receive an email to verify your email address for the domain name, or the domain name will be suspended. If you receive an email about failing to register the domain name, create an **Account and billing** support case with service **Domains** and category **Registration issue**. The issue should be resolved in 2-3 days.

## Creating records in Route 53 Hosted Zone

1. Select **Hosted zones** in the navigation pane and click the hosted zone created in the previous step.
![Hosted zones](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/myr82ned5dm6nmhbggt0.png)

2. Click **Create record**.
![Hosted zone](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6zve2ipuo903ge12p2i6.png)

3. Enter `www` as the subdomain, toggle on the switch for **Alias**, select **Alias to Elastic Beanstalk environment**, select the region of the environment, select the environment accordingly, keep other values default, and click **Create records**.
![Create record](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zqkf5mow1zjcz6yk6k2k.png)

## Updating the Django settings

1. Append the Route 53 domain name to the `ALLOWED_HOSTS` list in the file named `settings.py` in the `ebdjango` directory, and save the file.

    ```python
    ALLOWED_HOSTS = [
        "djangoproj-dev.eba-ttkddb9r.us-east-1.elasticbeanstalk.com",
        "www.elasticbeanstalkapp.com",
    ]
    ```

2. Re-deploy the Django site.

    `eb deploy`

After the environment update completes, the Django site is updated. At this stage, navigating to either the Elastic Beanstalk domain name (i.e. `http://djangoproj-dev.eba-ttkddb9r.us-east-1.elasticbeanstalk.com`) or the Route 53 domain name (i.e. `http://www.elasticbeanstalkapp.com`) gets the same Django site.

![Django Site](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6n5wof4c1wket7288m0d.png)

## References

- https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/domain-register.html#domain-register-procedure-section
- https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-beanstalk-environment.html