Running flask on AWS SAM

Frustrated learner ctippur at gmail.com
Fri Oct 13 00:19:58 EDT 2017


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.



More information about the Python-list mailing list