Bad gateway error for a Flask app deployed using Elastic Beanstalk

This is a super short post that outlines one specific solution for anyone trying to deploy a simple Flask application using AWS Elastic Beanstalk and hitting a bad gateway error.


The Internet has some good stuff on helping you if you made a mistake elsewhere, but I did not find this basic check being mentioned anywhere. Make sure that your flask application variable is within if __name__ == "__main__":.

I got lazy and initialized the application variable globally and was rewarded with a bad gateway error. Because I was new to the deploying apps using AWS Beanstalk, I ended up chasing all sorts of other hypothesis before checking if my app was being returned or not. What helped me, in the end, was to ssh into the EC2 instance behind the load balancer and check its logs.

So, if you are like me and struggling with a bad gateway error, perform this simple check before you go chasing after issues elsewhere.

Leave a Reply

Your email address will not be published.