DEV Community

Discussion on: Using external Python packages with AWS Lambda layers

Collapse
uraniumreza profile image
Nayeem Reza

Hey Matthew, I followed your instruction but somehow it's not working. I'm using a package named haversine, when I hit the API Gateway by using curl, I got this error:

{"errorMessage": "Unable to import module 'lambda_function': No module named 'haversine'", "errorType": "Runtime.ImportModuleError"}
Enter fullscreen mode Exit fullscreen mode

Any idea why it's happening? Or, how to solve this?

Collapse
mmascioni profile image
Matthew Mascioni Author

Hi Nayeem! Looks like the layer dependencies might not be available in your function. A few places this could've gone wrong:

  • Were there any errors raised while you were building dependencies using the Docker image?
  • Does the runtime Python version on your Lambda layer match the one of your Lambda function, and were there any errors raised when adding the layer to your function?
Collapse
uraniumreza profile image
Nayeem Reza

No, I haven't faced any error while building the Docker Image, also no errors while adding the layer to the function! And I'm using Python3.7 in both the function and layer runtime!

Thread Thread
mmascioni profile image
Matthew Mascioni Author

Super weird! Sorry it's been causing problems - are you able to share the code you're using for your function? I gave it a shot using the haversine package as well, hard-coded one of their examples in and it seemed to work - attached a gist of the function here (didn't use it with API Gateway though)