Run mysqlclient on Lambda

Overview

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

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'. ..

Pick up libmysqlclient.so.18

You will need libmysqlclient.so.18 for Amazon Linux2, so build it.

Container startup

docker run -it amazonlinux:2 bash

In the container

Enter libmysqlclient.so.18.

yum update -y
yum install -y gcc mysql-devel mysql-libs # /lib64/mysql/libmysqlclient.so.18 enters

Local PC

Copy libmysqlclient.so.18 locally with docker cp etc.

docker cp container:/lib64/mysql/libmysqlclient.so.18.0.0 local_path

Precautions when placing libmysqlclient.so.18 on Lambda

Since 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.

Example: When uploaded as a layer

The layer's files are expanded in / opt, but .so must be in the position of / opt / lib.

Example: If you want to mix in the source for Lambda

It will be expanded to / var / task, so create lib and put .so in it.

Recommended Posts

Run mysqlclient on Lambda
Run Python on Schedule on AWS Lambda
[Python] Run Headless Chrome on AWS Lambda
Periodically run a python program on AWS Lambda
Run Django on PythonAnywhere
Launch Lambda on Boto3
Run OpenMVG on Mac
Run BigQuery from Lambda
Run Jupyter on Ubuntu on Windows
Run Openpose on Python (Windows)
Run Tensorflow 2.x on Python 3.7
Run Python CGI on CORESERVER
Run unix command on python
Run IPython Notebook on Docker
Run YOLO v3 on AWS v2
Run CircuitPython on Seeeduino XIAO
Run Jupyter Notebook on windows
Run FreeBSD on Linux + qemu
Run OpenVino on macOS Catalina
Run YOLO v3 on AWS
lambda
Run MuJoCo on WSL (2) (also GUI)
Install and run dropbox on Ubuntu 20.04
Run Tensorflow natively supported on windows
Run a Linux server on GCP
Run TensorFlow Docker Image on Python3
How to run matplotlib on heroku
Run SwitchBot on Windows 10 with Bleak
Run Matplotlib on a Docker container
Run azure ML on jupyter notebook
Run headless-chrome on a Debian-based image
Run XGBoost on Bash on Ubuntu on Windows
Run TensorFlow2 on a VPS server
Run vmware horizon client on Debian
[Note] Run Django on Amazon Linux 2
Run PartiQL on Dynamodb via boto3
Run Keras on Google Colaboratory TPU
Run docker-compose on Amazon Linux2 on ARM64
Run Yocto on Ubuntu using QEMU.
Run Sesame on Sony's PaSoRi (RCS370)
Periodically run Python on Heroku Scheduler
Run cron on Amazon Linux (set on Linux)
Modules cannot be imported in Python on EC2 run from AWS Lambda
Run Radeon GPU on Windows on QEMU / KVM
Run servo with Python on ESP32 (Windows)
Run TensorFlow on a GPU instance on AWS
Run a local script on a remote host
Use Tabpy with Cloud Run (on GKE)
Install python library on Lambda using [/ tmp]
Run AzureKinect in Python on Christmas Eve.
Run bootgen on Debian GNU / Linux, Ubuntu
Run servomotor on Raspberry Pi 3 using python
Run flake8 and pytest on GitLab CI
Until pix2 pix-tensorflow is run on GCML
Run Keycloak on Amazon Linux 2 without Docker
Run py.test on Windows Anaconda and MinGW
Run Python code on A2019 Community Edition
How to run Cython on OSX Memo
Run Jupyter notebook on a remote server
Run matplotlib on a Windows Docker container
Run Python in C ++ on Visual Studio 2017