如何在 Python 中的 AWS Lambda 上使用 Stripe API

Wil*_* G. 4 amazon-web-services stripe-payments aws-lambda

我将在 AWS Lambda 上使用 Stripe api 构建一个后端。但我无法导入条带库。

import stripe
Run Code Online (Sandbox Code Playgroud)

这一行给了我这个错误。

{
  "errorMessage": "Unable to import module 'lambda_function'"
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助我吗?

小智 7

Stripe python 库需要安装到与您正在编写的 python 脚本相同的文件夹中。

执行此操作的 pip 命令是:

pip install --install-option="--prefix=/full/local/path/to/your/python/script" --upgrade stripe
Run Code Online (Sandbox Code Playgroud)

这实际上会将库安装到您指定路径中的“lib”文件夹中。将所有内容从 /full/local/path/to/your/python/script/lib/python2.7/site-packages 复制到 /full/local/path/to/your/python/script

您的目录将如下所示:

./main.py
./requests/
./requests-2.13.0-py2.7.egg-info/
./stripe/
./stripe-1.55.0-py2.7.egg-info/
Run Code Online (Sandbox Code Playgroud)

压缩这些文件,然后将该 ZIP 文件上传到 AWS Lambda。

我知道这个问题已经有一年多了,但它仍然没有答案,当我搜索同样的问题时仍然出现了这个问题,所以这是我解决它的方法。