Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 868
William G. Avatar asked Mar 13 '23 17:03

William G.


1 Answers

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.

like image 74
James Eberhardt Avatar answered Mar 20 '23 05:03

James Eberhardt