Miserlou / Zappa

Serverless Python
https://blog.zappa.io/
MIT License
11.89k stars 1.21k forks source link

Failed to find libmysqlclient.so.18 when using slim_handler #2208

Open philmade opened 3 years ago

philmade commented 3 years ago

This issue has been posted here and here but so far no fix.

When trying to use Postgres (psycopg2 and psyopg2-binary) it seems Zappa still tries to import libmysqlclient.so.18, which it cannot find, causing the program (in this case, Flask migration scripts) to hang, then exit.

This is a breaking issue for deployment It means that Flask projects connecting to Aurora using psycopg2 binaries cannot be deployed as this issue stops database migrations/interactions

The library should either be available automatically, or not included if its not needed. The fact the library cannot be found seems to create a breaking error.

Yes

Expected Behavior

Running a Flask-Migrate command works locally (with my local dependencies) works correctly. But when I call that command on the server via zappa, I get a breaking error which causes the program to hang. I expect to be able to run the command on the server the same way/in the same environment as I can run it locally. I'm expecting my command to work - it doesn't.

Actual Behavior

A 30 second command timeout, with this in the tail: [1612507108211] Instancing.. [1612507108215] Failed to find library: libmysqlclient.so.18 ...right filename?

If I add "include": []" to settings.json, the problem persists. This fix was suggested in the above mentioned threads, but it has not worked.

The line in question is below - see how it does not allow for overriding of include: [] with nothing.

https://github.com/Miserlou/Zappa/blob/ba20c850eeca00edd6ea39fda1ab976cfee193ea/zappa/handler.py#L105

Possible Fix

There is a possible fix for the problem listed here

                include = self.stage_config.get('include', [])
                if include is None:
                    settings_s += 'INCLUDE=[]\n'
                elif len(include) >= 1:
                    settings_s += "INCLUDE=" + str(include) + '\n'

Steps to Reproduce

Create a flask app which uses Postgres db, connect to it with Flask-sqlalchemy, write a script which wraps Flask-Migrate commands so they're callable from zappa, and invoke either migrate() or update() - anything that uses the postgresdb.

Your Environment