I'm trying to create a web project that is able to communicate with Amazon RDS. I know how to make a localhost project connect to a RDS with JDBC.
However, the problem is that I never tried to deploy my project (so that, for example someone can type somePage.com
, and go to my webpage).
I have an Amazon EC2 instance, and I've already written a simple hello world jsp page. I am able to compile it and run the Eclipse Web Dynamic Project using the installed Apache Tomcat Server, and then typing localhost:8080/somePage
then I can see my hello world popping up.
However, how do I deploy my project on this EC2 instance? I'm using Windows Server 2012 edition.
My whole idea is that once I have one AMI image all setup, then I can just use autoscale to scale my webpage with that AMI image.
Can anyone point me to the right direction?
Follow the steps below:
- Setup Apache Tomcat on your Amazon EC2 instance.
- Usually all you have to do is download the current version, unzip it, and start it by running
apache-tomcat-folder\bin\startup.bat
. (You can also donwload an installer and set it up as windows service. Check this link for more details).
- Make sure you test it before continuing (open its address on a browser, something like
http://yourinstaceaddress.com:8080/
).
- Export your web application
.war
file
- In Eclipse, right click on a Web project and select Export. Then select WAR file in the Export window and then select Next. Choose the project, the
.war
file name and folder to export. More detailed explanation can be found here and here (with pictures).
- Deploy the
.war
file to your Tomcat Server
- The, by far, simplest way to do this is to place your
.war
(say myapp.war
) file in your apache-tomcat-folder\webapps\
folder.
- There are other ways, like via Tomcat Manager. But they can be tricky and, as a new user, you should avoid them. (Don't worry: the simple method is ok for production deployment).
- Test your web app
- Visit the url: say your
.war
's name was myapp.war
. You should visit http://yourinstaceaddress.com:8080/myapp
That's it. If you ever edit the app, repeat steps 2-4 (but delete the webapps\myapp\
folder created before executing step 3).
Boxfuse does exactly what you want.
For you Java web application you literally only have to execute:
boxfuse create my-tomcat-app -apptype=load-balanced
boxfuse scale my-tomcat-app -capacity=1-16:t2-micro:cpu25-75
boxfuse run my-tomcat-app-1.0.war -env=prod
This will
- Configure your application to use an ELB
- Set it to autoscale between 1 and 16 t2.micro instances based on CPU usage (scale in at 25% and below, scale out at 75% and above)
- Create AMI containg Tomcat and your application ready to boot
- Create an ELB
- Create a security group with the correct ports
- Create an auto-scaling group
- Launch your instance(s)
Any subsequent update will be done as a zero downtime blue/green deployment.
For your domain, you can simply map your samepage.com DNS record to the CNAME of the ELB.
More info: https://boxfuse.com/blog/auto-scaling