Skip to content Skip to sidebar Skip to footer

Unable To Install Cvxpy Into Virtualenv For AWS Lambda

I am trying to run the cvxpy package in an AWS lambda function. This package isn't in the SDK, so I've read that I'll have to compile the dependencies into a zip, and then upload

Solution 1:

For installing cvxpy on windows it requires c++ build tools (please refer: https://buildmedia.readthedocs.org/media/pdf/cvxpy/latest/cvxpy.pdf)

On Windows:

pip install cvxpy --target python/lib/python3.7/site-packages

On Linux:

  • I created the same directory structure as earlier python/lib/python3.7/site-packages and installed the cvxpy and zipped it as shown below.
  • Later I uploaded the zip file to an S3 bucket and created a new lambda layer.
  • Attaching that lambda layer to my lambda function, I colud able to resolve the import issues failing earlier and run the basic cvxpy program on lambda.
mkdir -p alley/python/lib/python3.7/site-packages
pip install cvxpy --target alley/python/lib/python3.7/site-packages
cd alley
zip -rqvT cvxpy_layer.zip .

Lambda layer Image:

enter image description here

Lambda function execution:

enter image description here


Solution 2:

You can wrap all your dependencies along with lambda source into a single zipfile and deploy it. Doing this, you will end up having additional repetitive code in multiple lambda functions. Suppose, if more than one of your lambda functions needs the same package cvxpy, you will have to package it twice for both the functions individually.

Instead a better option would be to try Labmda Layers, where you put all your dependencies into a package and deploy a layer into your Lambda. Then attach that layer to your function to fetch its dependencies from there. The layers can even be versioned. :)

Please refer the below links:


Post a Comment for "Unable To Install Cvxpy Into Virtualenv For AWS Lambda"