Miserlou/Zappa

slim_handler: true fails deploying with terraform

Opened this issue · 1 comments

Context

My app is > 50Mo. So i tried to use slim_handler: true but without success.
The error in the aws logs are: 'unable to import module lambda: No module named lambda'

So i tried with a smaller app for testing and I'm able to deploy successfully it without slim_handler: true
Still on this smaller app, i tried slim_handler: true but the same error displays: 'unable to import module lambda: No module named lambda'

My entry file is lambda.py and the function is:

def handler(event, context):
       return awsgi.response(wsgi.application, event, context, base64_content_types={"image/png"})

In fact, when i use slim_handler: true, the zip works perfectly but because of this slim_handler it returns an issue.
this is some of my cmd in my ci-jobs:

    - python -m venv env;
    - source env/bin/activate;
    - pip install -r requirements.txt;
    - zappa package dev
    - aws s3 cp *.zip s3://$ARTIFACTS_BUCKET/$ARTIFACTS_BUCKET_PACKAGE_KEY

I saw that with slim_handler it creates a .zip file and a .tar.gz file.
In a normal way you would do a zappa deploy dev but in my case it's terraform doing it and i send to my S3 bucket only the zip file ( in my case this is the only file expected, can't send a tar.gz ), so my question is:
what is sent when it's a normal deploy with zappa deploy dev ?
What zappa does when it does the deploy ?
Does it send the zip and the tar.gz ?

How can reproduce their deploy with terraform ?

Another question: how do you get some traceback because the issue 'unable to import module lambda: No module named lambda' is quite light. Does not help me a lot :)

Expected Behavior

It should return OK:

def health_check(request):
  return HttpResponse(content="OK", status=200)

Actual Behavior

It returns {"message": "Internal server error"}
'unable to import module lambda: No module named lambda'

Possible Fix

Steps to Reproduce

Well, you won't be able to reproduce it as it's deploy with terraform

Your Environment

  • Zappa version used: 0.51.0
  • Operating System and Python version:Linux, Python 3.7
  • The output of pip freeze:
argcomplete==1.12.0
asgiref==3.2.10
aws-wsgi==0.2.7
boto3==1.14.60
botocore==1.17.60
certifi==2020.6.20
cfn-flip==1.2.3
chardet==3.0.4
click==7.1.2
Django==3.1.1
djangorestframework==3.11.1
docutils==0.15.2
durationpy==0.5
future==0.18.2
hjson==3.0.1
idna==2.10
jmespath==0.10.0
kappa==0.6.0
pip-tools==5.3.1
placebo==0.9.0
python-dateutil==2.6.1
python-slugify==4.0.1
pytz==2020.1
PyYAML==5.3.1
requests==2.24.0
s3transfer==0.3.3
six==1.15.0
sqlparse==0.3.1
text-unidecode==1.3
toml==0.10.1
tqdm==4.49.0
troposphere==2.6.2
urllib3==1.25.10
Werkzeug==0.16.1
wsgi-request-logger==0.4.6
zappa==0.51.0
  • Link to your project (optional):
  • Your zappa_settings.json:
{
    "dev": {
        "django_settings": "gdi.settings",
        "profile_name": "default",
        "project_name": "gdi-api",
        "runtime": "python3.7",
        "s3_bucket": "zappa-xu89app6f"
    }
}

I am experiencing the same with non-wsgi package. Just Unable to import module 'api': No module named api, api being my file with a lambda_handler

Update:
I think my bug is this #941, basically slim_handler doesn't play with lambda_handler.