简体   繁体   中英

Can I use MySQL from AWS Lambda in Python?

Is the MySQL connector for Python or some equivalent module available in a form I can zip up and included in an AWS Lambda function, or is that just asking for trouble? Apparently Lambda functions written in Node.js can use a builtin library to talk to MySQL on RDS, but I don't see an obvious way to do that in Python.

I wouldn't want to try to install something that takes a long time or requires any assumptions about the underlying operating system. On Windows at least, it's a whole separate installer.

Same question for Java: does this work out of the box, or are there machinations necessary to package a MySQL jar file?

I think I got it. Being on Windows added some steps.

I got Python 2.7.10, which comes with Pip. I then installed mysql-connector-python using the trick here .

If in some cases you need to uses native library (which mysql should have), you can uses pure python implementation using PyMySQL, and include it in the deployment package of lambda.

More detail on how to create deployment package for python is here https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html See the advanced version.

For java, I guess it will work out of the box as long as you include all dependency in jar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM