aws-lambda-builders: Unable to build Python lambda with package dependency in a private Git repository
Description:
I am trying to use sam build to build a Python 3.7 lambda. My requirements.txt file contains the following dependency:
git+ssh://git@github.com/Berciq/commons.git@v0.0.4
So, as you can see, I am trying to include a package hosted in a private Git in my requirements.txt file as per the documentation. The package installs fine when using pip install -r requirements.txt but sam build throws the following error:
Build Failed
Error: PythonPipBuilder:ResolveDependencies - list index out of range
If I remove that dependency from my requirments.txt, sam build runs successfully.
Steps to reproduce the issue:
- Use
sam initto create any Python-based AWS SAM application (e.g. hello-world) - Add a private Git repo dependency to the requirements.txt file
- Run
sam build
Observed result:
The build will fail with a PythonPipBuilder:ResolveDependencies error.
Expected result:
The build should succeed, given that running pip install -r requirements.txt succeeds.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc) I’m running Ubuntu 20, AWS SAM CLI v.1.26.
But I was also able to reproduce the problem by installing and importing aws-lambda-builders as a module and running the PythonPipWorkflow, hence I’m raising the issue here.
This appears to be related in some way to Issue #229 but at the same time it’s not exactly the same issue, as mine has to do specifically with dependencies hosted in a private repository.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 11
- Comments: 36 (8 by maintainers)
Also getting this error, with version 1.40.1, when specifying a private git repo in requirements.txt. I am using python 3.8.
To follow up on my last comment, I’m quite certain that the issue I’m experiencing on my system is caused by Python’s
sys.executablereturning the path of the SAM CLI executable as opposed to the path of the Python interpreter when executingsam build. The stacktrace fromsam build --debugreveals that the issue happens on the following lines:Here is why I believe this is the case:
sam build --debugincludes the following log message:This, along with the stack trace included in the output, makes it apparent that the above call to
subprocess.Popen()is trying to execute the command against the SAM CLI.sys.executablereturns:I would expect for the Python interpreter path to be undefined within a compiled binary such as the SAM CLI executable. What is odd, is that the
sys.executableis not returning an empty string or None, as per the documentation, which would result in a different and perhaps clearer error message. However, it actually makes sense thatsys.executableis returning the path to the compiled binary itself.samdev build, thereby confirming that the command works as expected when not in a compiled binary.I think that’s an accurate diagnosis of the issue. How to solve it? I’m not sure at this point. It seems that
sys.executablemay need to be substituted by a different approach for reliably obtaining the Python interpreter path.I am getting the same error:
Error: PythonPipBuilder:ResolveDependencies - Unable to retrieve name/version for package:with versionSAM CLI, version 1.37.0(latest) during the build process when specifying a dependency from a public github repo.I am able to reproduce this issue. We will work on a solution for this issue.
Any news on this? We get the Error: PythonPipBuilder:ResolveDependencies - Unable to retrieve name/version for package:… and the workaround setting up a local development environment (in no 3 above) seems a little cumbersome.
In my case
sam buildexpects asetup.pyfile to coexist with mypyproject.tomlfile before it will process the dependency.I used the
dephellutility to convert mypyproject.tomlfile to asetup.pyfile like this.With
setup.py, it works.sam buildgives this debug output. No error after the firstpip downloadcommand.Without
setup.py, it fails.sam buildgives this debug output that shows an error.To add to the previous comment, I’m able to successfully build this package inside Docker using the following command:
The SSH related params in the above command are necessary for Docker to use my local system’s SSH keys to fetch the sample-pkg package from my private repo. But the key thing to note is that
sam buildexecutes successfully within that Docker container.This leads me to think that the problem is in some way operating-system related or configuration related. I’m on Ubuntu 20.04.3 LTS.
Here is another thing I noticed. Please note how one of the debug messages says:
This error message is a result of executing this command.
The strange thing is that this command should be executing within the context of the Python interpreter, like so:
But instead, it appears to be executing within the context of
sam buildas indicated by the log message:So it appears that
sys.executablepoints to the SAM CLI executable on my system instead of the Python interpreter. Which is strange, because it doesn’t under normal circumstances. Here is the output from a simple test script:This is how far I’ve gotten so far troubleshooting this. Maybe someone can pick up where I left off and identify the root cause.
Hi @yasntrk, could you provide more information on your error? If its the one above to do with setup.py files thats because currently sam build doesn’t support pyproject.toml files and requires a setup.py instead.
If its to do with the original issue could you try running the commands again but using one of the versions of sam linked here https://github.com/sidhujus/aws-sam-cli/actions/runs/7011049269
The version of sam there includes the fix that was previously mentioned in this thread and did fix the error for me. Just make sure to run the command as
sam-beta build@iainelder
here’s a
setup.cfgfile that works for me with thesetup.pyabove. There’s othermetadatafields that are optional you might want to include like author & description. (replaced private info with{{}}placeholders)all the source code is located in “src/{{name}}” from the root of my repository where setup.cfg is located.
adding a setup.py to my private packages fixed the issue for me. I was using just
setup.cfgandpyproject.toml- thinking it wasn’t needed b/c of PEP 517/518I just needed to add the following to a
setup.pyto the project root (requires setup.cfg):Any idea when this gets merged? We have this issue happening to us both locally and within our pipelines. It’s really frustrating to use SAM with this.
Any updates on this?
Contrary to what I wrote earlier, I’m still facing this issue (or a related one) with SAM CLI version 1.34.1. The error message changed. Please see attached output of
sam build --debugbelow.I’m on Ubuntu 20.04.3 LTS.
Here is what my requirements.txt looks like:
And here is the output from
sam build --debug: