How to install pymysql on AWS lambda

后端 未结 3 936
名媛妹妹
名媛妹妹 2020-12-31 10:11

I\'ve looked here and here as I\'ve been trying to work out how to get pymysql running on AWS lambda. The examples I\'ve looked at so far are extremely complex,

相关标签:
3条回答
  • 2020-12-31 10:56

    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.

    0 讨论(0)
  • 2020-12-31 11:02

    I cannot directly comment on Aaron's response because I am a newby, so I add it here. TheYoungSoul has a hundred repos. The repo containing "create_deployment.py" is: AlexaDeploymentSample

    0 讨论(0)
  • 2020-12-31 11:12

    TheYoungSoul has a fantastic YouTube example of how to do this step-by-step. Once I followed these instructions this was pretty easy to do.

    Steps:

    1. Write a locally testable version of the routine I want to implement on lambda and call this function main.py. main.py has the function lambda_handler inside of it, which has the basic structure def lambda_handler(event, context): ...

    2. Use the script create_deployment.py, available on his repo, in conjunction with requirements.txt to create your deployment zip file. Note that if you're on a Mac and this errors out on the first try may need to do this.

    3. Once you have a locally testable example running, create your lambda function on AWS and instead of writing function from scratch select the console menu option to upload a .zip file.

    4. Make sure to create a custom role that has access to RDS resources and be sure to place the DB that you want to connect with in the same VPC group. When setting up your function, specify that you want your lambda function to have VPC access.

    0 讨论(0)
提交回复
热议问题