Search code examples
javaamazon-web-servicesdeploymentsubdomainweb-deployment

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


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


Solution

  • 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.