How do I invoke/deploy a serverless function with diesel and mysql?

Viewed 119

When I try to test out invoking a serverless function handler using the serverless-rust plugin I get the error

/usr/bin/ld: cannot find -lmysqlclient
collect2: error: ld returned 1 exit status
1 Answers

You will need to use the hooks in the lambda-rust docker builder to install the necessary dependencies and include the library files in the packaged build.

First create a directory at the root of the project named .lambda-rust and in it create two files:

install

#!/usr/bin/env bash

echo "installing mysql dependencies"
yum install -y mysql-devel

and package

#!/usr/bin/env bash

echo "packaging mysql library"
zip -j "$1.zip" /usr/lib64/mysql/libmysqlclient.so.18

Adjust the name of the library file for whichever is installed for you (I added a line with echo $(ls /usr/lib64/mysql) in one of the scripts to see what files existed after the install)

Related