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.