Jaymon / endpoints

Lightweight REST api backend framework that automatically maps urls to python modules and classes
MIT License
29 stars 10 forks source link

endpoints is not accessible outside aws #54

Closed Rafi993 closed 8 years ago

Rafi993 commented 8 years ago

I ran endpoints example in aws but it is not accessible outisde the ec2 instance. But when I tried running other applications it is accessible so it is not the problem of security groups related issue

Jaymon commented 8 years ago

If you ran the example in the codebase, you can see that it specifies localhost:8000, which won't be available remotely. You can test locally (on the box, using the command line) with curl:

$ curl -v "http://localhost:8000"

Next, you'll want to make sure your AWS EC2 security group allows port 8000, but because you said it "is not the problem of security groups" I'm going to assume you've done that, in which case my guess is it is because the example uses localhost, so you can modify the server.py script to use 0.0.0.0 instead of localhost.

You can also run this command (run it from the endpoints example directory):

$ sudo python ../endpoints/bin/wsgiserver.py --prefix=controllers --host="0.0.0.0:80"

That will run the endpoints's example controllers.py file using port 80, you can, of course, change 80 to whatever you want, but get rid of sudo if you use a port greater than 1024 (anything under that needs root privileges).

Rafi993 commented 8 years ago

If I ran the above command in endpoints example directory I get the following error

Traceback (most recent call last):
  File "../endpoints/bin/wsgiserver.py", line 76, in <module>
    sys.exit(console())
  File "../endpoints/bin/wsgiserver.py", line 70, in console
    s.serve_forever()
  File "/usr/local/lib/python2.7/dist-packages/endpoints/interface/wsgi.py", line 210, in serve_forever
    self.prepare()
  File "/usr/local/lib/python2.7/dist-packages/endpoints/interface/__init__.py", line 138, in prepare
    self.server = self.create_server()
  File "/usr/local/lib/python2.7/dist-packages/endpoints/interface/wsgi.py", line 201, in create_server
    s = self.server_class(server_address, WSGIRequestHandler, **kwargs)
  File "/usr/lib/python2.7/SocketServer.py", line 419, in __init__
    self.server_bind()
  File "/usr/lib/python2.7/wsgiref/simple_server.py", line 48, in server_bind
    HTTPServer.server_bind(self)
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 108, in server_bind
    SocketServer.TCPServer.server_bind(self)
  File "/usr/lib/python2.7/SocketServer.py", line 430, in server_bind
    self.socket.bind(self.server_address)
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
TypeError: an integer is required
Rafi993 commented 8 years ago

and could I achieve the same without using server.py?

Rafi993 commented 8 years ago

@Jaymon I was able to run endpoints --prefix=mycontroller --host=0.0.0.0:8000 and make it accessible outside aws. But still couldnt get server.py example running. Thanks for your help

Jaymon commented 8 years ago

Yeah, I forgot to mention you should upgrade to the latest version of endpoints (1.1.17) before trying that out, as there was a bug I noticed while double checking my examples. I'll take a look at the example and fix it. Thanks!