serverless-python-requirements
serverless-python-requirements copied to clipboard
mysqlclient and LD_LIBRARY_PATH with lambda layers
The steps mentioned in the documentation for mysqlclient
are not working as expected and is raising the following error
ImportError: libmysqlclient.so.1020: cannot open shared object file: No such file or directory
Dockerfile contents:
FROM lambci/lambda:build-python3.7
RUN yum -y install mysql57-devel
serverless-python-requriements config
pythonRequirements:
useDownloadCache: false
useStaticCache: false
dockerizePip: true
dockerFile: Dockerfile
dockerExtraFiles:
- /usr/lib64/mysql57/libmysqlclient.so.1020
layer:
name: ${self:service}-${self:provider.stage}-requirements-python37
compatibleRuntimes:
- python3.7
I have observed that even though, the layer has the files _mysql.cpython-37m-x86_64-linux-gnu.so
, libmysqlclient.so.1020
, at /opt/python
, we are still getting this error because the default LD_LIBRARY_PATH
in Lambda Python 3.7 Runtime doesn't consider /opt/python
, it only checks in the following paths.
/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib
I feel if there is provision to specify the destination path for the files mentioned in dockerExtraFiles
, this issue can be resolved.
I am running into the same issue. I worked around it by setting the LD_LIBRARY_PATH env variable
service: hello-lambda-vpc
frameworkVersion: '3'
plugins:
- serverless-python-requirements
package:
individually: false
patterns:
- "!*"
- "!*/**"
- main.py
custom:
pythonRequirements:
useStaticCache: false
dockerizePip: true
dockerFile: Dockerfile.build
dockerExtraFiles:
- /usr/lib/oracle/21/client64/lib/libociicus.so
- /usr/lib/oracle/21/client64/lib/libnnz21.so
- /usr/lib/oracle/21/client64/lib/libclntshcore.so.21.1
- /usr/lib/oracle/21/client64/lib/libclntsh.so.21.1
- /lib64/libaio.so.1
layer: true
noDeploy:
- invoke
- uvicorn
provider:
name: aws
runtime: python3.7
stage: ${opt:stage, 'stage'}
functions:
app:
handler: main.lambda_handler
environment:
LD_LIBRARY_PATH: /var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/python
layers:
- { Ref: PythonRequirementsLambdaLayer }
events:
- httpApi: "ANY /{proxy+}"
@jgriffith you saved my day! Thank you