quaint-oyster-63068
03/22/2023, 9:30 PM~/bin/pants package project/lambda_example.py . Any ideas?
21:23:38.17 [ERROR] 1 Exception encountered:
Engine traceback:
in `package` goal
in Create Python AWS Lambda - project:lambda
ProcessExecutionFailure: Process 'Building lambdex.pex from lambdex_default.lock' failed with exit code 1.
stdout:
stderr:
There were 2 errors downloading required artifacts:
1. lambdex 0.1.9 from <https://files.pythonhosted.org/packages/20/89/05c73da172c510299869e904543825222ffa990b719ffaba4bce2d1be0c4/lambdex-0.1.9-py2.py3-none-any.whl>
ModuleNotFoundError: No module named 'distutils.util'
2. pex 2.1.111 from <https://files.pythonhosted.org/packages/5d/08/89438cc626ec77a6f7dc3ab17cad581d14882a2f51a37d24c8a4c127e7bc/pex-2.1.111-py2.py3-none-any.whl>
ModuleNotFoundError: No module named 'distutils.util'gorgeous-winter-99296
03/22/2023, 9:33 PMpython3-distutils with apt.quaint-oyster-63068
03/22/2023, 9:33 PMsudo apt-get install python3-distutilsquaint-oyster-63068
03/22/2023, 9:34 PMgorgeous-winter-99296
03/22/2023, 9:34 PMapt install python3.9-distutils? 🙂quaint-oyster-63068
03/22/2023, 9:34 PMquaint-oyster-63068
03/22/2023, 9:36 PMgorgeous-winter-99296
03/22/2023, 9:37 PM./pants ? I assume the latter, but just to double-check.quaint-oyster-63068
03/22/2023, 9:38 PMgorgeous-winter-99296
03/22/2023, 9:41 PMquaint-oyster-63068
03/22/2023, 9:41 PM"Unable to import module 'lambda_function': No module named 'lambda_function'"
Am I supposed to name my lambda handler file and handler function a certain name? I'm just following the instructions here: https://www.pantsbuild.org/docs/awslambda-python and the file is named "lambda_example.py" and the function is named "example_handler.py" ; seems like my Lambda function couldn't find those or know about those?refined-addition-53644
03/22/2023, 9:47 PMpython_awslambda target?
Your handler should look like path.to.module:handler_func as described here
https://www.pantsbuild.org/docs/reference-python_awslambda#codehandlercodequaint-oyster-63068
03/22/2023, 10:05 PMquaint-oyster-63068
03/22/2023, 10:11 PMquaint-oyster-63068
03/22/2023, 10:19 PMpanads but when I'm trying to run my function, it's saying that the module can't be founquaint-oyster-63068
03/22/2023, 10:19 PMrefined-addition-53644
03/22/2023, 10:24 PM_requirements function like
python_requirements()
and you should have requirements.txt with your python packages in same directory where this is definedquaint-oyster-63068
03/22/2023, 10:24 PMquaint-oyster-63068
03/22/2023, 10:25 PMquaint-oyster-63068
03/22/2023, 10:25 PMquaint-oyster-63068
03/22/2023, 10:26 PMhandler field, which you can confirm by running pants dependencies path/to:lambda "refined-addition-53644
03/22/2023, 10:26 PMquaint-oyster-63068
03/22/2023, 10:27 PMquaint-oyster-63068
03/22/2023, 10:27 PMrefined-addition-53644
03/22/2023, 10:29 PMA target’s dependencies determines which other first-party code and third-party requirements to include when building the target.Usually, you leave off the
dependencies field thanks to dependency inference. Pants will read your import statements and map those imports back to your first-party code and your third-party requirements. You can run pants dependencies path/to:target to see what dependencies Pants infers.quaint-oyster-63068
03/22/2023, 10:34 PMrefined-addition-53644
03/22/2023, 10:35 PMlocal_module
import local_module #1st party
import pandas as pd #3rd partyquaint-oyster-63068
03/22/2023, 10:37 PMpants dependencies to get the list of 3rd party modules that are inferred, add that to the dependencies in my BUILD, then call pants package ?refined-addition-53644
03/22/2023, 10:39 PMquaint-oyster-63068
03/22/2023, 11:08 PMpython_requirements( source="requirements.txt"
• In my Lambda runtime settings, I had to set the handler to the auto-generated file and function name: lambdex_handler.handler
Still a bit confused about the 3rd party inference part for inferring pandas and numpy, as the docs makes it sound like those are auto-inferredgorgeous-winter-99296
03/23/2023, 9:15 AMpython_requirements bridges these, making Pants know about more things that it can infer from. So:
• add pandas to `requirements.txt`: Pants learns that pandas exists, where it comes from, etc
• add python_sources() to a directory: Pants learn those files exist
• when looking at a new file it'll see what it imports and try to find those from the things it knows about from before