Tomcat – Accessing Tomcat 8 on AWS EC2

amazon ec2tomcat

I know there are similar questions on Tomcat and EC2 alredy but unfortunately I cannot find anything that solves my apparently simple issue.
I have installed Tomcat 8 on an EC2 instance (HVM edition of the Amazon Linux AMI) with:

sudo yum install -y tomcat8

sudo yum install tomcat8-webapps tomcat8-docs-webapp tomcat8-admin-webapps

I can start Tomcat just fine:

sudo service tomcat8 start [OK] 

and connect locally to the default Tomcat welcome page:

wget http://localhost:8080 (returns 200OK and index.html)

My security group in AWS has the following entry:

Custom TCP Rule | TCP | 8080 | 0.0.0.0/0 (see screenshot)

But when I try to access tomcat remotely it doesn't work.

curl ec2-x-x-x-x.us-west-2.compute.amazonaws.com:8080

curl: (7) Failed to connect to
ec2-x-x-x-x.us-west-2.compute.amazonaws.com port 8080: Operation timed
out

I know nothing about iptables, but if it is of relevance this is what they look like on my ec2 instance:

sudo iptables --list
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

So, the question is, what do I need to change/configure to get remote access?
Thanks in advance!
/ola

Best Answer

Ok, I figured it out. If you follow the AWS get-started guide it instructs you to create a security group with the correct settings, but it doesn't point out (our at least I missed it) that your EC2 instance will not use this security group unless you explicitly tell it to do so.

After doing that it works just fine.

This is how to do it: see screenshot

Related Topic