title: How do I get a stack trace from Zappa with Python on AWS Lambda
body: <p>I'm using the Zappa framework <a href="https://github.com/Miserlou/Zappa" rel="nofollow">https://github.com/Miserlou/Zappa</a> with Python and Flask on AWS Lambda. When it raises an exception it appears in the CloudWatch log but is illegible to me. I do get a normal Flask stack trace returned from a HTTP GET in debug builds however.</p>
  
  <p>My question is how do I get a reasonable (Flask) stack trace in logs / from production code? When exceptions are raised in production all I have is log messages.</p>
  
  <p>Nice stack trace from HTTP GET:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/var/task/handler.py", line 96, in handler
      response = Response.from_app(app, environ)
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/Werkzeug/werkzeug/wrappers.py", line 865, in from_app
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/Werkzeug/werkzeug/wrappers.py", line 57, in _run_wsgi_app
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/Werkzeug/werkzeug/test.py", line 871, in run_wsgi_app
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/zappa/zappa/middleware.py", line 78, in __call__
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/app.py", line 1836, in __call__
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/app.py", line 1820, in wsgi_app
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-jvEYWI/flask-restful/flask_restful/__init__.py", line 271, in error_router
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/app.py", line 1403, in handle_exception
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-jvEYWI/flask-restful/flask_restful/__init__.py", line 268, in error_router
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/app.py", line 1817, in wsgi_app
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/app.py", line 1477, in full_dispatch_request
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-jvEYWI/flask-restful/flask_restful/__init__.py", line 271, in error_router
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/app.py", line 1381, in handle_user_exception
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-jvEYWI/flask-restful/flask_restful/__init__.py", line 268, in error_router
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/app.py", line 1475, in full_dispatch_request
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/app.py", line 1461, in dispatch_request
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-jvEYWI/flask-restful/flask_restful/__init__.py", line 477, in wrapper
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-v6XvIH/flask/flask/views.py", line 84, in view
    File "/private/var/folders/1j/5zcxjzkx29b8tfgrh2y90wt80000gn/T/pip-build-jvEYWI/flask-restful/flask_restful/__init__.py", line 587, in dispatch_request
    File "/Users/notacat/src/aws-lambda/zappa/controllers/error_controller.py", line 15, in get
  TestError: 'This is a test error'
  </code></pre>
  
  <p>Hard to understand stack trace from CloudWatch log:</p>
  
  <pre><code>...Rlc3RFcnJvcjogJ1RoaXMgaXMgYSB0ZXN0IGVycm9yJzxiciAvPjwvcHJlPg==: 
  Exception Traceback (most recent call last): 
  File "/var/task/handler.py", line 161, in lambda_handler return LambdaHandler.lambda_handler(event, context) 
  File "/var/task/handler.py", line 55, in lambda_handler return cls().handler(event, context) 
  File "/var/task/handler.py", line 155, in handler raise Exception(exception) 
  Exception: PCFET0NUWVBFIGh0bWw+NTAwLiBGcm9tIFphcHBhOiA8cHJlPidUaGlzIGl...
  </code></pre>