title: Deploying a Plotly/Dash app to AWS using Serverless Framework
body: <p>I am trying to deploy a Plotly Dash app as an AWS Lambda using Serverless framework. The app works as expected locally and I can start it using <code>serverless wsgi serve</code> command. <code>serverless deploy</code> reports success. However when invoked, lambda fails with the following error:</p>
  <pre><code>Traceback (most recent call last):
  File &quot;/var/task/wsgi_handler.py&quot;, line 44, in import_app
  wsgi_module = importlib.import_module(wsgi_fqn_parts[-1])
  File &quot;/var/lang/lib/python3.8/importlib/__init__.py&quot;, line 127, in import_module
  return _bootstrap._gcd_import(name[level:], package, level)
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1014, in _gcd_import
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 991, in _find_and_load
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 975, in _find_and_load_unlocked
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 671, in _load_unlocked
  File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 783, in exec_module
  File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed
  File &quot;/var/task/app.py&quot;, line 4, in &lt;module&gt;
  import dash
  File &quot;/tmp/sls-py-req/dash/__init__.py&quot;, line 5, in &lt;module&gt;
  from .dash import Dash, no_update  # noqa: F401,E402
  File &quot;/tmp/sls-py-req/dash/dash.py&quot;, line 21, in &lt;module&gt;
  from flask_compress import Compress
  File &quot;/tmp/sls-py-req/flask_compress.py&quot;, line 14, in &lt;module&gt;
  import brotli
  File &quot;/tmp/sls-py-req/brotli.py&quot;, line 8, in &lt;module&gt;
  import _brotli
  ModuleNotFoundError: No module named '_brotli'
  [ERROR] Exception: Unable to import app.server
  Traceback (most recent call last):
    File &quot;/var/lang/lib/python3.8/imp.py&quot;, line 234, in load_module
      return load_source(name, filename, file)
    File &quot;/var/lang/lib/python3.8/imp.py&quot;, line 171, in load_source
      module = _load(spec)
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 702, in _load
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 671, in _load_unlocked
    File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 783, in exec_module
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed
    File &quot;/var/task/wsgi_handler.py&quot;, line 119, in &lt;module&gt;
      wsgi_app = import_app(config)
    File &quot;/var/task/wsgi_handler.py&quot;, line 49, in import_app
      raise Exception(&quot;Unable to import 
  {}
  &quot;.format(config[&quot;app&quot;]))
  </code></pre>
  <p>app.py</p>
  <pre class="lang-py prettyprint-override"><code>import dash
  import dash_html_components as html
  from flask import Flask
  
  server = Flask(__name__)
  
  @server.route(&quot;/&quot;)
  def index():
      return &quot;Hello Flask app&quot;
  
  app = dash.Dash(
      __name__,
      server=server,
      routes_pathname_prefix='/dash/'
  )
  
  app.layout = html.Div(html.H1(&quot;Hello Dash!&quot;))
  
  if __name__ == &quot;__main__&quot;:
      server.run(debug=True)
  </code></pre>
  <p>serverless.yml</p>
  <pre class="lang-yaml prettyprint-override"><code>---
  service: dash-serverless
  
  variablesResolutionMode: 20210219
  useDotenv: true
  
  provider:
    name: aws
    runtime: python3.8
    stage: test
    region: eu-central-1
    apiGateway:
      shouldStartNameWithService: true
    lambdaHashingVersion: 20201221
  
  functions:
    app:
      handler: wsgi_handler.handler
      events:
        - http: ANY /
        - http: &quot;ANY {proxy+}&quot;
  
  custom:
    wsgi:
      app: app.server
      pythonBin: python3
      packRequirements: false
    pythonRequirements:
      dockerPip: non-linux
  
  plugins:
    - serverless-wsgi
    - serverless-python-requirements
  
  package:
    exclude:
      - node_modules/**
      # and other
  
  </code></pre>
  <p>requirments.txt</p>
  <pre><code>-i https://pypi.org/simple
  brotli==1.0.9
  click==7.1.2; python_version &gt;= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
  dash-core-components==1.15.0
  dash-html-components==1.1.2
  dash-renderer==1.9.0
  dash-table==4.11.2
  dash==1.19.0
  flask-compress==1.9.0
  flask==1.1.2
  future==0.18.2; python_version &gt;= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'
  itsdangerous==1.1.0; python_version &gt;= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
  jinja2==2.11.3; python_version &gt;= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
  markupsafe==1.1.1; python_version &gt;= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
  plotly==4.14.3
  retrying==1.3.3
  six==1.15.0; python_version &gt;= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
  werkzeug==1.0.1; python_version &gt;= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
  </code></pre>