I have a simple Java servlet based app running on port 8080 of a tomcat server in an EC2. When I click a button, it returns all user records in the database and renders them to the screen.
The app works fine when I deploy it on my localhost, with Tomcat, and it connects fine the RDS from which it's retrieving the user records.
However, when I deploy the WAR file to Tomcat on an EC2 instance and access it at http://51...***:8080/MyApp-0.0.1-SNAPSHOT, when I click the same button, it doesn't allow me to connect to my RDS and return the same objects.
The EC2 and RDS instance share the same availability zone, VPC (default), and security groups. I even added the EC2's private IP address to the security group that specifies inbound rules for both the RDS and EC2 (Inbound: Postgres 5432 139...*** ).
I am connecting to my EC2 via AWS EC2 Instance Connect (not through bash on my localhost since an RDS is a managed service). I have installed maven, jdk8, tomcat, and git on the ec2....do I need to install postgres as well?
After copying the war file to var/lib/tomcat/webapps
I run the app with sudo service tomcat start
and can access it at port 8080 at the address I mentioned above. (http://51.***.***.***:8080/MyApp-0.0.1-SNAPSHOT
).
Below are the security group inbound rules that both the EC2 and RDS instance share:
What am I doing wrong in terms of allowing the EC2 and RDS to talk to each other?
CodePudding user response:
Figured it out. Had nothing to do with Security groups or VPC. The servlet-based app in question is using URL rewriting to capture requests sent to http://543.251.123/AppToDeploy/...
final String URI = request.getRequestURI().replace("/AppToDeploy/", "");
switch(URI) {
case "login":
RequestHelper.processLogin(request, response);
break;
...
Within the EC2 instance, when I ran mvn clean package
it generated a WAR titled AppToDeploy-0.0.1-SNAPSHOT.war
, which I passed to Tomcat's webapps/
directory to serve on port 8080.
The fix was to add the following to my pom.xml
file to rename the packaged war file.
<build>
<!-- This renames the built war file -->
<finalName>${project.artifactId}</finalName>
</build>