简体   繁体   中英

How to create AWS Lambda deployment package that uses Couchbase Python client

I'm trying to use AWS Lambda to transfer data from my S3 bucket to Couchbase server, and I'm writing in Python. So I need to import couchbase module in my Python script. Usually if there are external modules used in the script, I need to pip install those modules locally and zip the modules and script together, then upload to Lambda. But this doesn't work this time. The reason is the Python client of couchbase works with the c client of couchbase: libcouchbase. So I'm not clear what I should do. When I simply add in the c client package (with that said, I have 6 package folders in my deployment package, the first 5 are the ones installed when I run "pip install couchbase": couchbase, acouchbase, gcouchbase, txcouchbase, couchbase-2.1.0.dist-info; and the last one is the c client of Couchbase I installed: libcouchbase), lambda doesn't work and said:

"Unable to import module 'lambda_function': libcouchbase.so.2: cannot open shared object file: No such file or directory"

Any idea on how I can get the this work? With a lot of thanks.

Following two things worked for me:

  • Manually copy /usr/lib64/libcouchbase.so.2 into ur project folder and zip it with your code before uploading to AWS Lambda.
  • Use Python 2.7 as runtime on the AWS Lambda console to connect to couchbase.

Thanks !

Unfortunately AWS Lambda does not support executing C-based python modules, like the Couchbase SDK.

Your best bet would be to use a pure-python client. The easiest way to do this would be to use the unofficial memcached client https://github.com/couchbase/couchbase-cli/blob/master/cb_bin_client.py which uses server-side moxi to handle memcached clients on port 11211.

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