Attach a Subdomain to an Elastic Beanstalk Environment with a .NET Core Web API

Justin Gerber
6 min readJul 31, 2022

--

So, let’s say that the reader has deployed a .NET Core Web API to Elastic Beanstalk on AWS.

First, let’s navigate to https://console.aws.amazon.com and sign in.

Once signed in, search for the Elastic Beanstalk service.

Find the Elastic Beanstalk environment that was uploaded.

In this guide a sample weather API was uploaded, and it can be accessed at weather-test-app-dev.us-east-1.elasticbeanstalk.com, seen in the screenshot below.

It would be great if this API could also be accessible at a domain that was purchased on GoDaddy. The author owns the domain justingerber.com. This guide will make this API accessible at https://weather.justingerber.com. This article will guide the reader to attach a subdomain to an Elastic Beanstalk Environment.

Prerequisites

The reader should have already purchased a domain from GoDaddy. If this step hasn’t been completed, then please follow the tutorial found at

https://medium.com/@justinshawngerber/buy-a-domain-from-godaddy-7fd67062931c

In this guide the justingerber.com domain was already purchased and will be used.

Create a Hosted Zone

A hosted zone represents a collection of records that are managed together in AWS, and they are tied to a single parent domain. If a hosted zone has not been created yet, the please follow steps below.

First, navigate to https://console.aws.amazon.com and sign in.

Once signed in, search for the Route 53 service.

Click on Hosted Zones on the left.

Click Create hosted zone.

Provide a Domain name of justingerber.com.

Click the Create hosted zone button.

Collect NS Record of Domain

First, navigate to https://console.aws.amazon.com and sign in.

Once signed in, search for the Route 53 service.

Click on Hosted Zones on the left.

Two records should be seen in the grid, seen in the image below. Take note of the NS record for justingerber.com. Specifically, copy these values:

ns-900.awsdns-48.net
ns-1745.awsdns-26.co.uk
ns-139.awsdns-17.com
ns-1261.awsdns-29.org

These values will be different for the reader. Please save these values in notepad or something similar. These values will be used in the next section.

Add NS Records in GoDaddy

Next, custom NS records will be added in GoDaddy so that it will point to the set of nameservers on AWS.

First, navigate to https://account.godaddy.com and sign in.

Click on My Products on the top toolbar.

Next, click on the DNS button on the justingerber.com domain.

Click the Add button.

Select NS in the type drop down list.

Type weather in the name textbox.

In the value textbox, type ns-900.awsdns-48.net.

Click Add Record.

Repeat the process for the other three NS records.

ns-1745.awsdns-26.co.uk
ns-139.awsdns-17.com
ns-1261.awsdns-29.org

Please note that the values came from the previous section. The reader should have their own ns records.

Once done, four NS records should be visible in the grid.

Certificate Manager

The AWS Certificate Manager is a service that can provision, manage, and deploy public and private (SSL/TLS) certificates in AWS services.

First, navigate to https://console.aws.amazon.com and sign in.

Once signed in, search for the Certificate Manager service.

Click on the Request button.

Ensure that the Request a public certificate radio button is selected.

Click on the Next button.

Set the Fully qualified domain name to weather.justingerber.com.

Ensure that the DNS validation radio button is selected.

Click the Request button.

Refresh the page. There should be a new record in the certificates grid. Notice that the status is Pending validation.

Click on the certificate ID for weather.justingerber.com

Click on the Create records in route 53 button.

Click on the Create records button. This will add a CNAME record in route 53.

Navigate back to the Certificate Manager service.

Wait until the status is issued. This can take several minutes. Please do not proceed until the status is Issued.

Custom Domains

Next, navigate to https://console.aws.amazon.com and sign in.

Once signed in, search for the API Gateway service.

On the left tab, click on Custom domain names.

Click Create.

For the Domain name, provide the value weather.justingerber.com.

For the ACM certificate, select the weather.justingerber certificate. This was just created in the previous section.

Click the Create domain name button.

Route 53 Add Type A Record

Next, navigate to https://console.aws.amazon.com and sign in.

Once signed in, search for the Route 53 service.

Click on the hosted zones link.

Click on the justingerber.com link in the grid.

Click the Create Record button.

For the record name provide weather.

For the record type drop down list ensure A is select.

Ensure that the Alias switch is on.

The first drop down list under Route traffic to should be set to Alias to Elastic Beanstalk environment.

Set the second drop down list under Route traffic to US East (N. Virginia)[us-east-1].

Set the third drop down list under Route traffic to weather-test-app-dev.us-east-1.elasticbeanstalk.com.

Click the Create records button.

Ensure an A and CNAME record is present in Route 53 for the weather app.

Adding SSL

First, navigate to https://console.aws.amazon.com/ and sign in.

Once signed in, search for the weather Elastic Beanstalk service.

Under the Environment Name column, click the Weather-test-app-dev app that was added.

Next, click the configuration option on the left menu.

Click the edit button under the capacity section.

Set the environment type drop down list to Load Balanced.

Click apply at the bottom of the page.

This warning tells us that AWS is going to redeploy the application.

Click the confirm button. This will take a few minutes to redeploy the application.

Wait for the health of the application to be healthy before proceeding.

Click on configuration option on the left menu.

Click the edit button under the load balancer section.

Click on the Add listener button.

Set the Listener port to 443.

Set the Listener protocol to HTTPS.

Set the Instance port to 80.

Set the Instance protocol to HTTP.

Set the SSL certificate to weather.justingerber.com

Click the Add button.

Important: Once this has been added, the changes have not been saved yet.

Scroll to the bottom of the page and click the Apply button.

Congratulations! The API is now accessible at https://weather.justingerber.com

--

--