Skip to content

Instantly share code, notes, and snippets.

@mfurlend
Created December 9, 2021 18:29
Show Gist options
  • Save mfurlend/f5126100fbd7b59de29d04fdf1021d41 to your computer and use it in GitHub Desktop.
Save mfurlend/f5126100fbd7b59de29d04fdf1021d41 to your computer and use it in GitHub Desktop.
Use native mysql client library in AWS Lambda through serverless

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):

  1. Download layers.zip from this repo https://github.com/nonbeing/mysqlclient-python3-aws-lambda/tree/master/build_output
  2. Move it to <project_root>/layers/mysqlclient.zip
  3. Add this to serverless.yml:
layers:
 mysqlclient:
   name: list-lambda-${opt:stage}-mysqlclient
   package:
     artifact: layers/mysqlclient.zip
functions:
 app:
   layers:
     - {Ref: MysqlclientLambdaLayer}
  1. Make sure that mysqlclient is in your Pipfile or requirements.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment