Non-native mysql clients such as pymysql perform much slower than the native mysql client. Here’s how to get the native client working with lambda (through serverless):
- Download layers.zip from this repo https://github.com/nonbeing/mysqlclient-python3-aws-lambda/tree/master/build_output
- Move it to <project_root>/layers/mysqlclient.zip
- Add this to serverless.yml:
layers:
mysqlclient:
name: list-lambda-${opt:stage}-mysqlclient
package:
artifact: layers/mysqlclient.zip
functions:
app:
layers:
- {Ref: MysqlclientLambdaLayer}
- Make sure that
mysqlclient
is in your Pipfile or requirements.txt