18

Using aws lambda I am receiving the following error when the script is run with the numpy module:

Unable to import module 'process': /var/task/numpy/core/multiarray.so: invalid ELF header

Is this problem related to numpy itself or numpy specifically on aws lambda. What is an invalid ELF header?

Edit:

I believe this is related to native code execution, as stated in this answer "invalid ELF header" when using the nodejs "ref" module on AWS Lambda

Community
  • 1
  • 1
Michael
  • 6,561
  • 5
  • 38
  • 55

2 Answers2

17

The problem has to do with the multiarray.so file which was complied on my local computer's architecture. Spin up an ec2 instance and create your virtualenv with the necessary dependencies. This will cause it to compile with the correct architecture as used by Aws lambda. Then download your virtualenv from the ec2 instance and use that for lambda.

Michael
  • 6,561
  • 5
  • 38
  • 55
  • So the solution was to start with a fresh EC2 instance, create virtual env, install numpy, and then zip up site-packages? Or did you zip up even more than that? – ZJS Jan 28 '16 at 17:06
  • Yes, I also added the compiled files which can be found in /lib64. – Michael Jan 28 '16 at 17:45
  • I just wanted to add that the EC2 instance to spin should be with name similar to (AMI name: amzn-ami-hvm-2016.03.3.x86_64-gp2) based on http://docs.aws.amazon.com/lambda/latest/dg/current-supported-versions.html. In case you don't know which one to create. – zeta Feb 01 '17 at 18:29
0

I had similar error :

/var/task/bcrypt/_bcrypt.so: undefined symbol: PyInt_FromLong

Previous answer didn't seem to work for my Pyhon:3.6 lambda.

I succeeded using this article : https://medium.com/i-like-big-data-and-i-cannot-lie/how-to-create-an-aws-lambda-python-3-6-deployment-package-using-docker-d0e847207dd6

Alexandre Hamon
  • 1,162
  • 12
  • 13