-2

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.

Community
  • 1
  • 1
darkavenger
  • 675
  • 1
  • 5
  • 11
  • From what it sounds, this has very little to do with Flask. This is more of a network/routing problem. You must ensure your remote server has routes and is able to send data to the EC2 server. http://www.thegeekstuff.com/2012/04/route-examples/. Once you have the routes in place, then simply listen on all ports or specify the interface and port using Flask. – notorious.no Jul 03 '16 at 07:37
  • I thought the same. But it did not work. I have set all ports open for all protocols and still its not connecting. – darkavenger Jul 03 '16 at 07:59
  • @notorious: yeah that worked.i changed the security settings and it worked. Thanks a lot – darkavenger Jul 04 '16 at 06:31

1 Answers1

1

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

Community
  • 1
  • 1
Alvin Wan
  • 540
  • 3
  • 11
  • Thanks a lot. But I am still not able to get it working. You are right about the port and I re-wrote the code to `app.run(host='0.0.0.0', port=8000)`. If `0.0.0.0` can be used for external devices, then the issue is in security settings. In securtiy setting as of now I gave access to All traffic in inbound rules. But that is still not working. Now one other doubt, I just want to clarify it. How do i connect to my EC2 server? right now am just typing my public ip in my browser along with the port number, `publicip:port#` or `PublicDNS:port#`. Is this right? what stupid mistake am I doing? – darkavenger Jul 03 '16 at 09:22
  • I played around with security settings and finally got it working. Thanks a lot for the answer. – darkavenger Jul 04 '16 at 06:30