Miserlou/Zappa

zappa packaging issue[timeout error and logging issue]

siva-annam opened this issue · 0 comments

Context

I have a sample flask application that I want to deploy on the AWS environment(API-Gateway+Lambda) using Zappa.
My project structure will be like this

Backend
     misc
        project1
        project2
        etc ....
     flask-project
        backend_logging.py
         main.py
         requirements.txt
         zappa_settings.json

zappa_settings.json file will be like this

{
    "dev": {
        "app_function": "main.app",
        "keep_warm" : false,
        "debug" : true,
        "log_level" : "DEBUG",
        "profile_name" : "dev",
        "aws_region": "us-east-1",
        "project_name": "flask-project",
        "runtime": "python3.6",
        "s3_bucket": "zappa_bucket_123",
        "use_precompiled_packages" : true
    }
}

My Requirements.txt file will be like this

-i https://pypi.org/simple
boto3
amazon-dax-client
cachetools
flask-bootstrap
flask-login
flask-wtf
flask
html2text
pycryptodomex
python-dateutil
python-dynamodb-lock
python-jose[cryptography]
pytz
pyyaml
requests
shopifyapi
urllib3
redis-py-cluster
msgpack
rule-engine
zstandard
inflection
pycryptodome
pyfiglet
pyparsing
pytest
ujson
zappa
gevent
werkzeug

i gone to Backend/flask-project/ path and performed these steps

virtualenv .venv
. .venv/bin/activate

pip3 install zappa
pip3 install -r requirements.txt

zappa package dev -o artifact.zip

After performing these steps, zappa created a zip file for me namely artifact.zip(around 80 MB)

My AWS environment has some CI/CD setup, so i just need to upload this artifact.zip file into S3. Then CI/CD will take care of invoking API Gateway and lambda whenever i send HTTP Request.

Expected Behavior

  1. whenever i send HTTP request, it needs to provide proper response
  2. whenever my flask code is running, it needs to write the logging messages present in my flask application into cloudwatch as logs

Actual Behavior

Issue-1
whenever i send HTTP request, after 29 seconds, it is returning as Execution failed due to a timeout error

Note:

  1. Based on my research, i found that API-Gateway has a time limit of 29 seconds. if API-Gateway didn't get any response from lambda with in 29 seconds, API Gateway returns timeout error
  2. Based on my research, i found another information. If the lambda function is large in size, it will take more time to process.

After knowing these two points, i thought of reducing the size of my zip file. I gone to zipped file and noticed that, whenever i run zappa package dev -o artifact.zip , it is not only packaging my flask application code it is also packaging misc(projects) which are available in upper level directory of my flask project

I tried using exclude option of zappa_settings.json but no success. i endup with 80MB zip file .

Here i want a way to only package my flask application code and requirments necessary for this application not other project codes
When i send the HTTP request, i want proper response not timeout errors

Issue-2
when i see the cloudwatch logs of lambda function, i am seeing logging messages present in my flask application as print messages in cloudwatch not in the form of logs.
for example

Expected logging behaviour:
2020-11-01T15:31:43+0000 - DEBUG - - PROCESSING - START : processing started siva

Actual logging behaviour:
2020-11-01T15:31:43+0000  - - PROCESSING - START : processing started siva

if we see above example, i am seeing logging mesages present in my flask-application but there is no information about whether it is DEBUG,INFO OR ERROR etc.

Possible Fix

I don't have any idea.

Your Environment

  • Zappa version used: zappa 0.52.0
  • Operating System and Python version: Linux and Python 3.6
  • The output of pip freeze:
  • Link to your project (optional):
  • Your zappa_settings.json:

Can any one suggest a solution for this?