2

I'm just starting to test out deploying my spring boot webapp onto AWS. I've currently got a t2.micro (1vcpu/1gb) running Ubuntu server and I've packaged my app into a fat jar using mvn clean install.

The tomcat server initially deploys fine and I can access my APIs remotely, however, after a few hours (haven't managed to time it accurately), the server seems to stop on its own. I login to the instance and the java process seems to have stopped on its own.

The command I use to run the jar is the typical java -jar xxxxx.jar.

The app has 2 entities, 2 controllers, 3 services. Nothing complex.

Currently still using h2 as the db as I'm just testing some stuff out, but the db initializes empty with no data.

From what I've read on other threads, this sounds like a OOM issue. Contributing factor being the h2 db which is an in-mem db.

However, it's a really small app and as mentioned the db starts out empty. So doubting if it's consuming that much RAM beyond a few 100mbs. The idle server consumes ~23% of RAM, with ~500mb in cache and ~300mb free.

Also I'm not able to find logs on the server which say it's killed the java process due to OOM. (I searched in var/logs/dmesg)

I haven't tried deploying it on something bigger yet, but wanted to get some insights before going in the wrong direction.

Will post my java code if it adds context. Thanks in advance.

fabbbles
  • 65
  • 6
  • Are you just logging in via SSH and starting the app via your SSH console session? If so the session is probably timing out and killing the process. You should look into running it as a background service. Is the app currently configured to log to the console? If so you should redirect the console output to a log file when you start the app so that you can view the Spring Boot logs later for things like OOM errors. You should also check the instance's metrics in CloudWatch to see if you are exhausting the CPU credits of the t2 server or anything. – Mark B Jul 18 '21 at 17:57
  • Yes indeed I am. Will look into running it as a background service, and configure logs to go into a file. Thanks for the suggestion. Will keep this thread posted. – fabbbles Jul 19 '21 at 01:59

1 Answers1

0

To make sure you Spring BOOT app works, you can build the FAT JAR and then try using Elastic Beanstlak - which puts the app onto an EC2 instance. See this AWS tutorial for information. It uses various AWS Services, including DynamoDB. But you can skip the code part and read the deployment section:

Creating the DynamoDB web application item tracker

See the environment variables that also need to be set.

smac2020
  • 9,637
  • 4
  • 24
  • 38
  • Thanks for the tip. The app actually works when I deploy it manually on my EC2 instance. Just that it seems to stop after awhile. I'll try Mark's suggestion above and see if the issue is due to the SSH session. – fabbbles Jul 19 '21 at 03:55
  • @fabbbles was the issue SSH related? I'm going to deploy my own spring boot app on EC2 very soon and i'm very interested to know what caused your issue. – Maurice Jan 13 '22 at 22:20
  • 1
    @Maurice, the issue was due to the app being run in the foreground and it was getting terminated after sometime. I used the nohup command to start the java process in the background and it was fine after that. https://stackoverflow.com/questions/10408816/how-do-i-use-the-nohup-command-without-getting-nohup-out – fabbbles Jan 20 '22 at 01:54