简体   繁体   English

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

[英]How to use Stripe Apis on AWS Lambda in Python

I am going to build a backend using Stripe api on AWS Lambda.我将在 AWS Lambda 上使用 Stripe api 构建一个后端。 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. Stripe python 库需要安装到与您正在编写的 python 脚本相同的文件夹中。

The pip command to do this is:执行此操作的 pip 命令是:

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.这实际上会将库安装到您指定路径中的“lib”文件夹中。 Copy everything from /full/local/path/to/your/python/script/lib/python2.7/site-packages to /full/local/path/to/your/python/script将所有内容从 /full/local/path/to/your/python/script/lib/python2.7/site-packages 复制到 /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.压缩这些文件,然后将该 ZIP 文件上传到 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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