简体   繁体   中英

Unable to import module 'lambda_function': No module named 'orjson.orjson'",

I'm trying to run a Python Lambda function (which ran successfully in 3.6, and I'm now trying to upgrade to a supported version). I'm getting this result:

Response
{
  "errorMessage": "Unable to import module 'lambda_function': No module named 'orjson.orjson'",
  "errorType": "Runtime.ImportModuleError",
  "stackTrace": []
}

The orjson library is presumably a dependency of one of my dependencies, as I'm not importing it directly. I have tried to include all necessary dependencies as a layer, and I have experimented with a variety of ways to structure the zip file with the dependencies installed, but this issue persists.

Is there anything I might be overlooking when creating the zip file for the layer?

I have been struggling with the same issue, and found out today that it is because orjson is built on my Mac while AWS Lambda uses Amazon Linux, making the orjson 's cpython artifact incompatible when deployed.

Try using --use-container option when running sam build . This builds the artifact on an Amazon Linux container, and has resolved the issue for me.

Hope this helps.

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