Running flask on AWS SAM
Hello, I have a flask based application which i am able to run locally. $ python swagger_server/app.py * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) I am trying to port this over to aws. I have all the dependencies and code organized in the same folder. Here is the transaction and error: $ SERVER_NAME=0.0.0.0:3000 sam local start-api 2017/10/12 21:02:20 Connected to Docker 1.32 2017/10/12 21:02:20 Fetching lambci/lambda:python3.6 image for python3.6 runtime... python3.6: Pulling from lambci/lambda Digest: sha256:c77ea3986c471c2f93dfa2a86492e6306989505073795da3b22defa2b10846a6 Status: Image is up to date for lambci/lambda:python3.6 Mounting swagger_server.app.app (python3.6) at http://127.0.0.1:3000/current [GET] Mounting static files from public at / You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template. 2017/10/12 21:02:30 Invoking swagger_server.app.app (python3.6) 2017/10/12 21:02:30 Decompressing /Users/shekartippur/playground/cyclopscloud/cyclopsglobal/swagger_server.zip START RequestId: 9518afce-6cf7-4f20-9a31-0a60907b5467 Version: $LATEST 'SERVER_NAME': KeyError Traceback (most recent call last): File "/var/task/connexion/apps/abstract.py", line 266, in __call__ return self.app(environ, start_response) File "/var/task/flask/app.py", line 1997, in __call__ return self.wsgi_app(environ, start_response) File "/var/task/flask/app.py", line 1977, in wsgi_app ctx = self.request_context(environ) File "/var/task/flask/app.py", line 1938, in request_context return RequestContext(self, environ) File "/var/task/flask/ctx.py", line 242, in __init__ self.url_adapter = app.create_url_adapter(self.request) File "/var/task/flask/app.py", line 1765, in create_url_adapter server_name=self.config['SERVER_NAME']) File "/var/task/werkzeug/routing.py", line 1299, in bind_to_environ wsgi_server_name = environ['SERVER_NAME'] KeyError: 'SERVER_NAME' END RequestId: 9518afce-6cf7-4f20-9a31-0a60907b5467 REPORT RequestId: 9518afce-6cf7-4f20-9a31-0a60907b5467 Duration: 3257 ms Billed Duration: 3300 ms Memory Size: 0 MB Max Memory Used: 38 MB I looked up the error and dint find much help. Wondering what I could be missing. -- https://mail.python.org/mailman/listinfo/python-list
Re: Running flask on AWS SAM
Any takers? -- https://mail.python.org/mailman/listinfo/python-list
Re: Running flask on AWS SAM
export SERVER_NAME="0.0.0.0:3000 sam local start-api" just exports everything and does not execute. I tried export SERVER_NAME="0.0.0.0:3000" sam local start-api comes back with the same error. Shekar -- https://mail.python.org/mailman/listinfo/python-list
Running flask server under virtualenv
Hello, I am using Python 3.62 on a mac. I am working under a virtualenv. I generated server code via http://editor.swagger.io (Swagger UI) Steps to reproduce python3 -m venv flaskglobal source flaskglobal/bin/activate cp binary to flaskglobal and unzip contents cd python-flask-server pip install -r requirements.txt python -m swagger_server I am getting the following error when running flask server. I have a model called binary. I am guessing a path issue. In the model, the code is: from __future__ import absolute_import from swagger_server.models.binary import Binary ## <-- Error from .base_model_ import Model from datetime import date, datetime from typing import List, Dict from ..util import deserialize_model . Error: from .binary import Binary File "/Users/ctippur/cyclops/cyclopscloud/flaskapi/cyclopsflaskglobal/python-flask-server/swagger_server/models/binary.py", line 4, in from swagger_server.models.binary import Binary Here is the tree for swagger server that got generated via swagger UI (http://editor.swagger.io) ├── Dockerfile ├── README.md ├── git_push.sh ├── requirements.txt ├── setup.py ├── swagger_server │ ├── init.py │ ├── main.py │ ├── pycache │ │ ├── init.cpython-36.pyc │ │ ├── main.cpython-36.pyc │ │ ├── encoder.cpython-36.pyc │ │ └── util.cpython-36.pyc │ ├── controllers │ │ ├── init.py │ │ └── default_controller.py │ ├── encoder.py │ ├── models │ │ ├── init.py │ │ ├── pycache │ │ │ ├── init.cpython-36.pyc │ │ │ ├── base_model_.cpython-36.pyc │ │ │ ├── binary.cpython-36.pyc │ │ │ └── body.cpython-36.pyc │ │ ├── base_model_.py │ │ ├── binary.py Swagger declaration file content or ur Could this be a pythonpath issue? -- https://mail.python.org/mailman/listinfo/python-list
Re: Running flask server under virtualenv
My bad. I was playing around with it. It should be: from swagger_server.models.binary import Binary -- https://mail.python.org/mailman/listinfo/python-list
Re: Running flask server under virtualenv
Here is the complete stack trace Traceback (most recent call last): File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/Users/ctippur/cyclops/cyclopscloud/flaskapi/cyclopsflaskglobal/python-flask-server/swagger_server/__main__.py", line 4, in from .encoder import JSONEncoder File "/Users/ctippur/cyclops/cyclopscloud/flaskapi/cyclopsflaskglobal/python-flask-server/swagger_server/encoder.py", line 2, in from swagger_server.models.base_model_ import Model File "/Users/ctippur/cyclops/cyclopscloud/flaskapi/cyclopsflaskglobal/python-flask-server/swagger_server/models/__init__.py", line 5, in from .binary import Binary File "/Users/ctippur/cyclops/cyclopscloud/flaskapi/cyclopsflaskglobal/python-flask-server/swagger_server/models/binary.py", line 4, in from swagger_server.models.binary import Binary ImportError: cannot import name 'Binary' -- https://mail.python.org/mailman/listinfo/python-list