Using moviepy, scipy and numpy in amazon lambda

I was also following your first link and managed to import numpy and pandas in a Lambda function this way (on Windows):

  1. Started a (free-tier) t2.micro EC2 instance with 64-bit Amazon Linux AMI 2015.09.1 and used Putty to SSH in.
  2. Tried the same commands you used and the one recommended by the Amazon article:

    sudo yum -y update
    sudo yum -y upgrade
    sudo yum -y groupinstall "Development Tools"
    sudo yum -y install blas --enablerepo=epel
    sudo yum -y install lapack --enablerepo=epel
    sudo yum -y install Cython --enablerepo=epel
    sudo yum install python27-devel python27-pip gcc
    
  3. Created the virtual environment:

    virtualenv ~/env
    source ~/env/bin/activate
    
  4. Installed the packages:

    sudo ~/env/bin/pip2.7 install numpy
    sudo ~/env/bin/pip2.7 install pandas
    
  5. Then, using WinSCP, I logged in and downloaded everything (except _markerlib, pip*, pkg_resources, setuptools* and easyinstall*) from /home/ec2-user/env/lib/python2.7/dist-packages, and everything from /home/ec2-user/env/lib64/python2.7/site-packages from the EC2 instance.

  6. I put all these folders and files into one zip, along with the .py file containing the Lambda function.
    illustration of all files copied

  7. Because this .zip is larger than 10 MB, I created an S3 bucket to store the file. I copied the link of the file from there and pasted at “Upload a .ZIP from Amazon S3” at the Lambda function.

  8. The EC2 instance can be shut down, it’s not needed any more.

With this, I could import numpy and pandas. I’m not familiar with moviepy, but scipy might already be tricky as Lambda has a limit for unzipped deployment package size at 262 144 000 bytes. I’m afraid numpy and scipy together are already over that.

Leave a Comment