- Create an IAM user with programmatic access.
- Download AWS CLI https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
- Setup your AWS account :
aws configure
- Download & install python https://www.python.org/downloads/ (I recommend using a virtual enviornment via micromamba/conda or venv)
- Download aws Beanstalk CLI :
pip3 install awsebcli
Let's say we have a root domain (eg: mlprojects.ai
) hosted on some domain name provider (eg: https://www.namecheap.com/ , https://www.godaddy.com/ etc).
Our goal is to create a subdomain on AWS Route53 without having to migrate the root domain mlprojects.ai
to Route53.
To do so, we need to do the following :
- Create a Route53 Hosted zone for the subdomain (eg:
staging.mlprojects.ai
)
- Copy/Take note of the value of the NS record that was created automatically by Route53, it contains the DNS Server Names for the subdomain.
- Navigate to the domain name provider of your root domain (eg: https://www.namecheap.com/ or any other). In this example, the root domain is
mlprojects.ai
. - Navigate to the DNS settings and create a new record of type
NS
for every DNS Server Name from step 2.
This essentially enables the subdomain delegation from the root domain name provider to Route53.
This is the only change required for the root domain name provider configuration, everything from now on will be done on Route53 and we won't have to edit the root domain name provider configuration.
- Navigate to AWS Certificate Manager (ACM)
- Click to "Request" an HTTPS certificate using AWS Certificate Manager (ACM)
- Select public certificate
- Enter the fully qualified domain name as your subdomain :
staging.mlprojects.ai
- Click "Request"
- From the ACM click "Create records in Route53" in the certificate details page.
This will allow Route53 to validate ownership.
After a few minutes, AWS will have issued your certificate upon confirming ownership.
From the ACM certificates page you should see that your certificate is issued and not in use :
- For the purpose of this example, a basic python application was created in
application.py
.
Here we create an application called myapp
that uses the platform (AWS predefined env) python-3.8
under the region us-east-1
:
eb init myapp --platform python-3.8 --region us-east-1
These steps follow the AWS documentation and the config file is taken from the official AWS repository.
- Create a folder for the beanstalk configuration, it has to be named
.ebextensions
at the root of your project. You can learn more about this configuration folder here : https://docs.amazonaws.cn/en_us/elasticbeanstalk/latest/dg/environment-configuration-methods-before.html#configuration-options-before-ebextensions - Create a
.config
file under the.ebextensions
folder that will contain the environment resources options (see the filestaging-resources-options.config
from this repo). - Edit the
CertificateArn
from the.ebextensions/staging-resources-options.config
file by entering the ARN of the ACM Certificate created earlier. - Create the environment :
eb create staging-env --region us-east-1 --elb-type application
Here we created an environment calledstaging-env
in the regionus-east-1
that has a load balancer of typeapplication
.
For more information on what is an Appliation Load Balancer see the AWS documentation
Note that the configuration in the.config
file presented earlier expects a load balancer of typeapplication
.
If you did subdomain delegation follow these steps:
These steps follow the AWS documentation
- Navigate to the subdomain Route53 Hosted Zone (eg:
staging.mlprojects.ai
) - Click "Create a record"
- Leave the
Record name
blank
- Leave the
Record type
to typeA
- Toggle the "Alias" toggle
- Under
Route traffic to
selectAlias to Elastic Beanstalk environment
. - Select the region you deployed your Beanstalk environment (eg:
us-east-1
). - Select your Beanstalk environment from the dropdown :
- Click "Create records"
Visit your application using the subdomain url you used when you created the Route53 Hosted Zone (eg: https://staging.mlprojects.ai/
)
Follow https://montanawong.medium.com/how-to-point-your-custom-domain-to-an-aws-load-balancer-51dc2eb6d84c