Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python3/cloud9/lambda - making imported modules available to lambda

Using sqlobject. When I import the module I get a unable to load module error when running lambda local or remote. The module is installed and if I get a command line python3 interpreter and import the module it imports just fine.

How do I get 3rd party modules installed so they work with both lambda local and lambda remote?

Code could not be simpler:

import sqlobject
like image 410
Eric Snyder Avatar asked Dec 10 '17 22:12

Eric Snyder


1 Answers

Answering my own question... These are instructions for Python 3.

First start with an empty environment, mine was called cycles.

Create a new lambda function:

enter image description here

Your folder structure now looks like this:

enter image description here

There will be two folders with the same name (a bit confusing - ask AWS not me).

Right button click on the top most folder with your lambda function name and select "Open terminal here". This gets you command line.

No need to use sudo, just install the packages you need. Install your packages into that folder:

python3 -m pip install --target=./ sqlobject

IMPORTANT You need to install the packages in that top folder that you opens a terminal from. See the part of the pip install line that says:

--target=./

that makes sure the packages get installed in the right folder that lambda can use. If you use the standard pip install:

python3 -m pip install sqlobject

You packages will be installed in the wrong place.

Your folder structure should look like this with the new added packeges installed: enter image description here

You can see the code to the right...it ran fine with the sqlobject package installed.

like image 173
Eric Snyder Avatar answered Sep 28 '22 03:09

Eric Snyder