Today’s Mozart Analytics BIT made me lose more than 2 hours and the solution was right in front of my face… as always!. If you have read our posts and blogs you may know by now that we are great fans of developing all our web apps and RESTful services using Grails and deploying them to our favorite cloud: Amazon Webservices (AWS). Grails is a Java-based framework so, in order to deploy our applications, the easiest way to go is by using the
grails war command that outputs it inside a WAR file ready to be used in a Java Servlet container such as Tomcat. We use AWS Elastic Beanstalk as our application container and manager of choice. In fact, we are running all of our production services inside AWS Beanstalk containers.
Well, here is the thing! Recently, AWS added a new Java-based environment type that I had not seen before. So I assumed that it was a new name for the previously existing Tomcat environment type which is the one we always used before. I selected it from this dropdown:
and continued with the process. Then, after the environment was created and the app was running green; when I navigated to the app, I got the dreaded 502 http code!
I didn’t know what was happening and started debugging my app in my dev environment. I did some changes to some parts that I thought that were causing this issue and redeployed (first lost hour). 502 again!
So I started googling and found out that sometimes when this error happens it is because the server is low on memory. So I selected a bigger instance and redeployed… 502! Then I found another forum post discussing that the new AWS Beanstalk Java environment uses an nginx reverse proxy and that it connects to the app using port
5000 by default. On the other hand, Grails standalone apps run using the standard
8080 port. So I continued with my research and found how to change the default Grails port to
5000 using an Environment variable. Then, when I started with the configuration changes it hit me! I thought “why would AWS do this and remove the Tomcat environment! it makes no sense at all!”. So I decided to recheck the Environment Type dropdown and there it was! The Tomcat configuration type, I have missed it all over (sometimes I think I am a little bit dislexic)! So here is today’s BIT:
When you get a 502 when navigating to your app deployed in AWS Beanstalk, make sure you are using the correct environment type before doing anything else!!!!
… hope this helped you save some time!!