Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zappa not packaging nested source directories

I have a python application that I am trying to deploy with zappa. The root level of my directory has the application and a directory named helper. The structure looks like this:

|-app.py
|-zappa_settings.json
|-helper
   |-api.py
   |-__init.py__

Within the helper directory there is an api.py file that is referenced in my app.py like so

from helper import api

When I run the command to package and deploy using zappa deploy dev it will not bundle the helper directory in the deployment, only the root level application directory. How do you tell zappa to include all sub-directories when packaging and deploying?

like image 708
medium Avatar asked Aug 27 '17 14:08

medium


1 Answers

After struggling with this myself, I realized that the idea is to package up your other code, install it in your virtual environment, and have app.py just be a driver that calls your other functions.

Here's a concrete minimum example using Flask. First, let's extend your example with one more file, setup.py:

|-app.py
|-zappa_settings.json
|-setup.py
|-helper
   |-api.py
   |-__init.py__

__init__.py is empty. The rest of the files are as follows:

# setup.py
from setuptools import setup

setup(
    name='helper',
    packages=['helper'],
    include_package_data=True,
    install_requires=['flask']
)


# app.py    
from helper import api
from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return api.index()


# helper/api.py
def index():
    return "This is the index content"


# zappa_settings.json
{
    "dev": {
        "app_function": "app.app",
        "s3_bucket": "my_bucket"
    }
}

Now you pip install -e . while in your virtual environment. If you now run app.py using Flask and go http://127.0.0.1:5000/, you'll see that you get This is the index content. And if you deploy using Zappa, you'll see that your API endpoint does the same thing.

like image 127
David Bruce Borenstein Avatar answered Nov 18 '22 23:11

David Bruce Borenstein