1

I have a flask app that I am depoying on an EC2 instance. The app starts just fine:

ubuntu@ip-something:~/webservices$ python service/texting_service.py 
 * Serving Flask app "texting_service" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 146-396-474

When I ssh into this EC2 instance and call the service using localhost, it returns the expected response. However, when I try to call this service from outside the EC2 instance using the instance's public IP address I see this error:

curl: (7) Failed to connect to ec2.instance.ip.address port 8080: Connection refused

I confirmed that I have opened the ingress port 8080 for the security group attached to this EC2 instance. What am I missing?

Darth.Vader
  • 5,079
  • 7
  • 50
  • 90

1 Answers1

6

I figured it out. If you do not pass the parameter host with value 0.0.0.0 in the app.run() function, the app is not visible externally. Doing the following resolved my issue:

if __name__ == '__main__':
    app.run(host='0.0.0.0')
Darth.Vader
  • 5,079
  • 7
  • 50
  • 90