Problems using MySQL with AWS Lambda in Python

后端 未结 9 1066
南方客
南方客 2020-12-05 17:43

I am trying to get up and running with AWS Lambda Python (beginner in Python btw) but having some problems with including MySQL dependency. I am trying to follow the instruc

相关标签:
9条回答
  • 2020-12-05 18:33

    Using lambda-docker you can set up and test your Lambda functions without access to a like-wise Linux environment.

    To set up your lambda, use a lambda-docker build image to run a detached docker container and run pip install <package> commands on the container. Then export the container, grab the installed packages under usr/lib, and place them in your AWS Lambda package.

    Then you can test for compatibility by running your lambda on a lambda-docker image. If it works, go forth and upload to AWS Lambda with confidence.

    docker run -d -v "$PWD":/var/task lambci/lambda:build-python2.7 tail -f /dev/null 
    
    docker ps
    
    docker exec 0c55aae443e6 pip install pandas
    
    docker exec 0c55aae443e6 pip install sqlalchemy
    
    docker exec 0c55aae443e6 pip freeze
    
    docker exec 0c55aae443e6 python -c "import site; print(site.getsitepackages())"
    
    docker container export -o lambda_ready_container 0c55aae443e6
    
    0 讨论(0)
  • 2020-12-05 18:35

    Lambda -> Layers (add new layer)

    download zip of pymysql from https://pypi.org/project/PyMySQL/#files

    when you download, unzip then rename parent folder to "python" then rezip (should be python/{where the pysqlfiles are}

    add a layer to Lambda called 'pymysql' and upload that zip

    then in Lambda function import pymysql

    0 讨论(0)
  • 2020-12-05 18:36

    I believe your issue is mostly down to missing development packages. I think you will need the following:

    sudo yum -y install mysql-devel

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