I am not an expert in web programming and know very little about it. I am trying to run a webservice on an EC2 instance (Windows Server 2012R2) and the webservice is written in Python using Flask package. I am able to connect to my webservice from localhost. But what I want to do is to connect it from a remote system which is NOT on the same network.
I learned from this link, that changing the line to app.run(host='0.0.0.0')
will let all devices on SAME network to connect to my webservice. But like I said, I want to connect from a system which is NOT on the same network. How can I do that in Flask? Also I have not installed Apache. Is that necessary to run a webservice?
Any suggestions would be really helpful. Thanks a lot.
Let A be the server you connecting to. Let B be the server you are connecting from, which, from what I gather, is sometimes localhost.
Why can't B connect to A?
1. Security Settings
The following is EC2-specific: You have to open up connections to specific IPs. Check your instance's security settings. If you added a security group to your EC2 instance, add your IP or the IP of the server to it. Otherwise, make sure to whitelist the IP for B.
2. Port
I'm not entirely sure this is what you want, but if everyone should be able to access A, you should run the Flask app on port 8000
. If only B (and possibly your localhost) should be able to access A, then ignore this paragraph...
0.0.0.0 allows devices on the SAME network to connect
Automagically, yes. Incidentally, this is the IP you should be pointing to, for other servers to connect too. So in your case, point to 0.0.0.0
too.
Is Apache necessary?
No, Apache is not necessary. You can persist a Flask development server if you want. (a.k.a. You can use python run.py
and just leave that process running for a "web service") In this case specifically, you don't need Apache to make this work. In the long-term, you will want Apache or Nginx to run your webservice however.
Here's a tutorial you can use to get Apache2 setup with Python. Just ignore the MySQL parts: https://www.digitalocean.com/community/tutorials/how-to-set-up-an-apache-mysql-and-python-lamp-server-without-frameworks-on-ubuntu-14-04