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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With