lambci / docker-lambda

Docker images and test runners that replicate the live AWS Lambda environment
MIT License
5.83k stars 431 forks source link

Trouble Using Layers on Python3.7 #307

Closed lucasconnellm closed 3 years ago

lucasconnellm commented 4 years ago

Hey, wanted to start by saying this is a super neat project! Great job!

Anyways, like the title says, I'm trying to test a python3.7 function with layers. However, when I try to run my function:

docker run --rm \
  -v /home/lconnell/ltester/first_test:/var/task:ro,delegated \
  -v /home/lconnell/.lambda_layers/google_api_layer:/opt:ro,delegated \
  lambci/lambda:python3.7 \
  lambda_function.lambda_handler

I am met with the following errors:

Error processing line 1 of /opt/python/lib/python3.7/site-packages/google_api_core-1.17.0-py3.8-nspkg.pth:

Traceback (most recent call last): File "/var/lang/lib/python3.7/site.py", line 168, in addpackage exec(line) File "", line 1, in File "", line 580, in module_from_spec AttributeError: 'NoneType' object has no attribute 'loader'

Remainder of file ignored Error processing line 1 of /opt/python/lib/python3.7/site-packages/google_auth-1.15.0-py3.8-nspkg.pth:

Traceback (most recent call last): File "/var/lang/lib/python3.7/site.py", line 168, in addpackage exec(line) File "", line 1, in File "", line 580, in module_from_spec AttributeError: 'NoneType' object has no attribute 'loader'

Remainder of file ignored Error processing line 1 of /opt/python/lib/python3.7/site-packages/googleapis_common_protos-1.51.0-py3.7-nspkg.pth:

Traceback (most recent call last): File "/var/lang/lib/python3.7/site.py", line 168, in addpackage exec(line) File "", line 1, in File "", line 580, in module_from_spec AttributeError: 'NoneType' object has no attribute 'loader'

Remainder of file ignored START RequestId: cd05f3b5-0a1f-1add-4971-49b3b3ac0012 Version: $LATEST [ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'oauth2client' END RequestId: cd05f3b5-0a1f-1add-4971-49b3b3ac0012 REPORT RequestId: cd05f3b5-0a1f-1add-4971-49b3b3ac0012 Init Duration: 909.25 ms Duration: 3.43 ms Billed Duration: 100 ms Memory Size: 1536 MB Max Memory Used: 32 MB

{"errorType":"Runtime.ImportModuleError","errorMessage":"Unable to import module 'lambda_function': No module named 'oauth2client'"}

I know that my layer is configured alright for Lambda, as I've used it on Lambda before. Any help is appreciated!

mhart commented 4 years ago

Is there an issue with python3.8 modules being used on python3.7? I'm seeing google_api_core-1.17.0-py3.8-nspkg.pth in that first line

mhart commented 4 years ago

Also, from stackoverflow, just wondering if deleting the .pth files works: https://stackoverflow.com/a/56935782

mhart commented 4 years ago

Seems like it's a common issue with google packages: https://stackoverflow.com/a/48025664

lucasconnellm commented 3 years ago

@mhart So sorry to waste your time, turns out my layer was dependent on another one of my layers. Just merged those two layers and tried again, it works now. Always the little things.

Also, didn't even realize that py3.8 thing. Must be some mislabeling. When you pip install google-api-core on 3.7, that's what you get.

Thanks!