Skip to content

Unable to import module “lambda_function”: No module named “pymysql”

If you receive the following error message when trying to run pymysql on AWS Lambda:

Unable to import module "lambda_function": No module named "pymysql" then you can fix this by running a Custom Lambda Layer.

To do this, you can boot up an EC2 instance (or a Linux instance anywhere else) and run the following set of commands:

#create module directory mkdir -p temp/python cd temp/python #install pymysql module pip install pymysql -t . cd .. #create a zip file using installed module zip -r9 ../ . #create the lambda layer aws lambda publish-layer-version --layer-name pymysql \ --description "pymysql for mysql access" \ --zip-file fileb://../ \ --compatible-runtimes python3.8
Code language: Bash (bash)

Once this is done, you will be able to head back to AWS Lambda, click on Layers and view your custom layer waiting there for you to use!

Now you can associate your lambda function to use this custom lambda layer.

See also  How to Check OS version and flavor in Linux
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x