AWS Lambda questions

偶尔善良 提交于 2020-01-06 19:52:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!