When using Python with Lambda, if you use a MySQL client that uses mysqlclient
(SQLAlchemy, etc.), you need to make various preparations.
mysqlclient
uses 1.4.6
libmysqlclient.so.18
from AmazonLinux2libmysqlclient.so.18
to Lambda, place it in the library path on Lambdamysqlclient
uses 1.4.6
pip install mysqlclient===1.4.6
I don't know the detailed principle, but when I try to use 2.0.1
, I get angry without'_mysql'. ..
libmysqlclient.so.18
You will need libmysqlclient.so.18
for Amazon Linux2, so build it.
docker run -it amazonlinux:2 bash
Enter libmysqlclient.so.18
.
yum update -y
yum install -y gcc mysql-devel mysql-libs # /lib64/mysql/libmysqlclient.so.18 enters
Copy libmysqlclient.so.18
locally with docker cp
etc.
docker cp container:/lib64/mysql/libmysqlclient.so.18.0.0 local_path
libmysqlclient.so.18
on LambdaSince the path of the library on the Lambda container is ↓,
LD_LIBRARY_PATH=/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib
You need to ensure that libmysqlclient.so.18
is placed in the above path when it is placed in your Lambda container.
The layer's files are expanded in / opt
, but .so
must be in the position of / opt / lib
.
venv / lib / site-packages
, put .so
in venv / lib / site-packages / lib
.It will be expanded to / var / task
, so create lib
and put .so
in it.
Recommended Posts