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

余生长醉 提交于 2019-11-29 07:25:10

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:

Your folder structure now looks like this:

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:

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!