简体   繁体   中英

How to use Stripe Apis on AWS Lambda in Python

I am going to build a backend using Stripe api on AWS Lambda. But I can't import stripe library.

import stripe

This line gives me this error.

{
  "errorMessage": "Unable to import module 'lambda_function'"
}

Anybody can help me?

The Stripe python libraries need to be installed to the same folder as the python script you are writing.

The pip command to do this is:

pip install --install-option="--prefix=/full/local/path/to/your/python/script" --upgrade stripe

This will actually install the libraries into the "lib" folder in the path you indicated. Copy everything from /full/local/path/to/your/python/script/lib/python2.7/site-packages to /full/local/path/to/your/python/script

Your directory will then look something like this:

./main.py
./requests/
./requests-2.13.0-py2.7.egg-info/
./stripe/
./stripe-1.55.0-py2.7.egg-info/

Zip up those files and then upload that ZIP file to AWS Lambda.

I know this question is over a year old, but it's still unanswered, and is what still turned up when I searched for this same problem, so here is how I solved it.

要使用 --target 添加到 James Eberhardt 的答案中,会将文件直接放置到所需位置。

pip install --target="/full/local/path/to/your/python/script" --upgrade stripe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM