Assign domain names with Route53
You can give your VM or stack a domain name or URL ex: www.myappdomain.com for easier access using AWS Route53 service.
Preparation
Please complete the below steps first:
- Register a domain. If your domain is registered with another registrar you can still use the AWS Route53 by Migrating your DNS service to Amazon.
- Configure Amazon Route53 as your DNS service
- Create a Hosted Zone
You will need the Zone ID of your Hosted Zone, you can find it by following these steps
Full Stack
provider:
aws:
access_key: '${var.aws_access_key}'
secret_key: '${var.aws_secret_key}'
resource:
aws_instance:
mars-webserver:
instance_type: t2.nano
user_data : |-
apt-get -y update
apt-get -y install nginx
aws_eip:
mars-webserver-eip:
instance : "${aws_instance.mars-webserver.id}"
aws_route53_record:
web :
zone_id : XXXXYYYYZZZZ
name : "${var.koding_user_username}.koding.team"
type : "A"
ttl : "60"
records : ["${aws_eip.mars-webserver-eip.public_ip}"]
Explanation
- Preparing & creating our VM and install nginx
resource:
aws_instance:
mars-webserver:
instance_type: t2.nano
user_data : |-
apt-get -y update
apt-get -y install nginx
- We create an Elastic IP for our VM to make sure the IP does not change on machine restart
aws_eip:
mars-webserver-eip:
instance : "${aws_instance.mars-webserver.id}"
If your VM is inside a VPC, you will need to set
vpc: true
in theaws_eip
section
- Next we setup our Route53 section parameters
aws_route53_record:
web :
zone_id : XXXXYYYYZZZZ
name : "${var.koding_user_username}.koding.team"
type : "A"
ttl : "60"
records : ["${aws_eip.mars-webserver-eip.public_ip}"]
Notes:
web
: the section name, you can choose any name - requiredzone_id
: the Zone ID you fetched from Amazon - requiredname
: the DNS record name, this will be your domain, or URL. We are using the user’s koding id followed by our domain, this will translate to logged-user.koding.team - requiredtype
: the DNS record type - requiredttl
: the time to live - requiredrecords
: a string list of IP records. We are using our assigned Elastic IP - required
Once you set all your records you should be able to access your VM web service from the new domain. In our case, the user building the stack was Alison, her Koding username is “Alison40” and our registered domain is koding.team, therefore her VM url is alison40.koding.team