Monday, February 26, 2018

Amazon web services AWS: how to host java app, assign custom domain, custom domain name doesn't work properly

Leave a Comment

I have a site hosted here: http://testapp-test.us-west-2.elasticbeanstalk.com/someservlet.do

The site contains an index.jsp and a someservlet.

In https://my.freenom.com cabinet I tried: to set nameservers and to set url forwarding to http://testapp-test.us-west-2.elasticbeanstalk.com. The former doesn't work: I set the nameservers as the screen shows and when trying to access codingrecords.tk it is just blank. URL forwarding however works, and it does display the main page, but when I try to access http://codingrecords.tk/someservlet.do it still displays the index.jsp message.

How do I fix it? By specifying nameservers, rather than url forwarding? But then it doesn't work too..

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

3 Answers

Answers 1

OK, so after lots of googling and trying out, I managed to make it work. I hope it will help future readers.

What I have done to deploy my java application in the custom domain in the Internet:

  1. Get free domain in freenom.com
  2. Create a key pair (don't know if it's necessary, just in case):
    2.1. Go to Amazon Web Services - Services - EC2 - Key Pairs - Create Key Pair

    enter image description here

    enter image description here

    enter image description here

    2.2 Pick a some key_name for the key, save a file on your computer

  3. Create an application and environment on AWS

    3.1 Go to Amazon Web Services - Services - Elastic Beanstalk - Create New Application

    enter image description here

    enter image description here

    3.2 Proceed to create new application, click next unless forced to fill something out; pick tomcat as a web server along the way; when come to a form where there's a Key label - pick an existing key with a name you assigned to it previously.

Pick a name - Next - Create Web Server - Select platform Tomcat - Next - Upload you .war file - Next - if you don't need a DB, click Next - set EC2 key pair to the key_name - Next - don't do anything with Environment Tags - Next - Next - Launch

3.3 Your application is lanched; you can see it at Elastic Beanstalk dashboard and you can see the running environment at Services - EC2 - Instances:

enter image description here

  1. Create IP address:

    4.0 Go to Services - EC2 - Instances. Check the IPv4 Public IP column. If there's already an address there, go to point 5. If it's empty go to 4.1.

    4.1 Go to Services - EC2 - Elastic IPs: enter image description here

    4.2 Click Allocate New Address:

    enter image description here

    4.3 Pick it and click Actions - Associate Address - Select your app's instance - Associate:

    enter image description here

  2. Set up Route 53:

    5.1 Go to Services - Route 53: enter image description here

    5.2 Go to Hosted Zones:

    enter image description here

    5.3 Click Create Hosted Zone:

    enter image description here

    5.4 Add your site's name to the form on the right (for instance, butterflies.com, somesite.edu, whatever):

    enter image description here

There appears a table with two record sets for your hosted zones: NS and SOA record sets.

5.5 Click on NS record set and copy paste nameservers from Value to your registrat's settings:

enter image description here

enter image description here

enter image description here

5.6 Go to Services - Elastic Beanstalk, find your application - copy URL value:

enter image description here

Go back to Route 53, Click Create Record Set. Choose Type: A, Alias: yes, in the Alias target paste the URL. Click Create:

enter image description here

5.7 Click Create Record Set. Set name: www. Set type: CNAME. Set value to your_site_name.your_domain (for instance, butterflies.com), click Create:

enter image description here

  1. It's done! Chances are, your_site_name is working.

Answers 2

So you only need 1 Public Route 53 zone for codingrecords.tk, then you can create a Route 53 resource record set for the sub domain www by creating an ALIAS record for the ELB given to you by Elastic Beanstalk.

Since you did create a route 53 zone for www.codingrecords.tk, I would delete that one(www.codingrecords.tk), Create a Delegation Name set with the name servers below, use that name set when you create the Route 53 zone for codingrecords.tk. That way you don't need to change the NS records at the Registar.

dig @8.8.8.8 www.codingrecords.tk NS  ; <<>> DiG 9.8.3-P1 <<>> @8.8.8.8 www.codingrecords.tk NS ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38463 ;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0  ;; QUESTION SECTION: ;www.codingrecords.tk.      IN  NS  ;; ANSWER SECTION: www.codingrecords.tk.   21599   IN  NS  ns-1363.awsdns-42.org. www.codingrecords.tk.   21599   IN  NS  ns-2005.awsdns-58.co.uk. www.codingrecords.tk.   21599   IN  NS  ns-62.awsdns-07.com. www.codingrecords.tk.   21599   IN  NS  ns-657.awsdns-18.net.  ;; Query time: 134 msec ;; SERVER: 8.8.8.8#53(8.8.8.8) ;; WHEN: Sun Feb 18 18:05:38 2018 ;; MSG SIZE  rcvd: 177 

No name servers for codingrecords.tk

dig @8.8.8.8 NS codingrecords.tk  ; <<>> DiG 9.8.3-P1 <<>> @8.8.8.8 NS codingrecords.tk ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 55760 ;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0  ;; QUESTION SECTION: ;codingrecords.tk.      IN  NS  ;; Query time: 156 msec ;; SERVER: 8.8.8.8#53(8.8.8.8) ;; WHEN: Sun Feb 18 18:15:39 2018 ;; MSG SIZE  rcvd: 34 

Answers 3

Just changing Name in the last record to www.codingrecords.tk. should make it work. If it doesn't - then read below and see what else is wrong.

As this is elastic beanstalk, you should have an ELB configured for it. And all you need to do is add an A record for www.codingrecords.tk configured as an alias to your ELB.

And if you want http://codingrecords.tk to work as well, you need to add an A record for it as well (also aliased to either your ELB). But also see P.S. below. Not sure why it even worked for you - it's not present in your configuration above and it doesn't resolve when I try from my machine. Most likely you have it in your /etc/hosts or your local DNS, or something else to that effect.

I believe CNAME records should work too. But I never tried. To me, A type seems to be a slightly better choice in Route 53 as you can still configure it as an alias (thus ripping all the benefits of CNAME), but AWS will still return an actual IP address to a query, saving end user a round-trip in name resolution.

P.S. I also believe your NS and SOA records were meant to be for codingrecords.tk, not for www.codingrecords.tk. Whilst perfectly valid in your current configuration, they essentially saying that you own www.codingrecords.tk (and it's sub-domains), but not codingrecords.tk. I don't think this was your intention.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment