Deploying Web Application on EC2 Instance- AWS

In this post, we will deploy spring web application on EC2 Amazon Linux AMI t2.micro instance following below steps:

Step 1: Set up Amazon EC2 instance following set-up-amazon-ec2-instance.

Step 2: Launch an EC2 instance following ec2-launch-linux-instance.

Step 3: Upload .war file from local machine directory to EC2 user home (/home/ec2-user) directory using secure copy as follows:

scp -i /Users/ArpitAggarwal/arpitaggarwal-key-pair.pem /Users/ArpitAggarwal/hello-spring/target/hello-spring.war

arpitaggarwal-key-pair.pem refers to private key file. refers to public dns name of EC2 instance.

Step 4: Connect to your EC2 instance using your private key file and public dns name as follows:

ssh -i /Users/ArpitAggarwal/arpitaggarwal-key-pair.pem

Step 5: Install Tomcat7 on EC2 instance as a root user:

[ec2-user@ip-10-0-0-28 ~]$ sudo su root
[ec2-user@ip-10-0-0-28 ~]$ yum install tomcat7

Step 6: Copy .war file from ec2-user home directory to webapps folder of tomcat, as follows:

[root@ip-10-0-0-28 ec2-user]# cp hello-spring.war /usr/share/tomcat7/webapps/

Step 7: Edit the JAVA_HOME in /etc/tomcat7/tomcat7.conf to point to JDK 7, replacing

# Where your java installation lives


# Where your java installation lives

Step 8: Start tomcat as follows:

[root@ip-10-0-0-28 ec2-user]# start tomcat7

Step 9: As tomcat is running on port 8080, we have to allow 8080 port from security group. To do that, from your instance, find out the security group associated and edit the security group adding another Type as Custom TCP Rule, Protocol as TCP, Port Range as 8080 and Source as Anywhere.

Now, access the web application from your browser using public dns name of your ec2 instance as:

The complete source code of spring web application is hosted on github.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s