box / box-python-sdk

Box SDK for Python
http://opensource.box.com/box-python-sdk/
Apache License 2.0
418 stars 215 forks source link

Module not found - _cffi_backend when running lambda with any python ver higher than 3.6 (boxsdk[jwt]?) #740

Closed widesides closed 1 year ago

widesides commented 2 years ago

We're running a lambda via CloudFormation that is using this sdk

requirements.txt

requests
boxsdk[jwt]
boxsdk

Everything runs fine when we use a lambda runtime of 3.6. The only problem with this is that AWS is deprecating 3.6 this summer. I would still like to be able to update the lambda if I need to later (it will still run on a deprecated version--it just won't allow me to update anything). I would like it to be on python3.9 at least.

The build process is fine. But when I try to run the lambda (with version >3.6), I get this error message:

{   "errorMessage": "Unable to import module 'lambda_function': No module named '_cffi_backend'",   "errorType": "Runtime.ImportModuleError",   "requestId": "<request-id>",   "stackTrace": [] }

I've been working with our internal cloud team and they've had me try a few different things like adding cffi directly to the requirements file and also trying cffi==1.15.0 etc. Those solutions unfortunately did not work. Doing something like this didn't make sense to my use case because it is a cloudformation and I don't see how I would be adding layers to a lambda cf (other than doing something with requirements.txt) unless I'm just not familiar with doing that?

We reached out to our Box contacts and they recommended opening an issue directly with you. We think it might have something to do with boxsdk[jwt] but we're honestly not sure how to proceed at this point.

Jeff-Meadows commented 2 years ago

The Stackoverflow question you linked presents one solution to what seems to be the underlying problem: the package being built and deployed to Lambda isn't compatible with its infrastructure/runtime.

boxsdk[jwt] depends on cryptography which in turn depends on cffi, which is very much platform-dependent (meaning, when pip goes to install cffi it does different things depending on which platform it's running on). So if the package is built on one platform, it probably won't work on another platform. For example, if it's built on a developer's machine, it wouldn't work on lambda.

I'm not sure how you're building the package that's getting deployed, but to solve this problem, you either need to

I hope this helps.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not been updated in the last 30 days. It will be closed if no further activity occurs within the next 7 days. Feel free to reach out or mention Box SDK team member for further help and resources if they are needed.

stale[bot] commented 1 year ago

This issue has been automatically closed due to maximum period of being stale. Thank you for your contribution to Box Python SDK and feel free to open another PR/issue at any time.