Aaron Aaron - 8 months ago 135
Python Question

How to install pymysql on AWS lambda

I've looked here and here as I've been trying to work out how to get

running on AWS lambda. The examples I've looked at so far are extremely complex, and with the GitHub tutorial I got as far as IAM before I started running into permissions errors I didn't know how to solve.

Literally, all I want to be able to do is call
import pymysql
within the prebuilt AWS lambda console template.

It seems like a simple problem, but I'm having a hard time finding a clear, step-by-step work through of how to get new dependencies to work for my lambda function. Ideally the example would not by via AWS CLI, since apparently there is a console option and this seems like it would take some of the headache out of the process.



Answer Source

I was facing similar problem with Redis python library. I follow the same documentation instructions which you mentioned in your second link.

here is example snippet for your reference :

Create new directory MyPythonLambda and put MyPythonLambda.py in the same.

Assume MyPythonLambda/MyPythonLambda.py is main lambda containing handler.

 cd MyPythonLambda/
 pip install redis -t .
 zip -r MyPythonLambda.zip *

Upload/import zip in lambda creation from S3 or your local file system.

I think you need to create zip file in similar way containing your python mysql library.