问题
I am using AWS Lambda as a backend - however I cannot figure out how to interact with my SQL database on Amazon RDS.
I would simply like to be able to write API function inLambda to access and retrieve information from the database.
To do this in python i would normally use the 'MySQLdb' module - however Lambda does not have this.
Any suggestions?
回答1:
If you you want to use external libraries, you need to create a deployment package that contains them and upload it via AWS console or S3.
More information here: http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html
回答2:
You have 2 options.
Option 1
Like Vladimir mentioned, you have to package MySQLdb
module along with your Lambda code and import MySQLdb
in your Lambda code.
Option 2
Use Boto3 RDS module which is included in Lambda/Python. No need to package anything extra. Just import boto3
. One drawback is you have rewrite your code using boto3 instead MySQLdb
来源:https://stackoverflow.com/questions/35479897/aws-lambda-questions