You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"sam build" feedback: Support private PyPi repositories #794
Hi @jfuss just wanted to check whether you have any recent updates on this? My use case is slightly different as I have private github repos so I'd need to pass in a github token (or ssh key) and build within the container. This is essentially the same to the question I've found on stack overflow here
We have a workaround. Since SAM is using PIP under the covers. We just generate as part of the build system a pip.conf in the correct directory. When SAM runs, and pip is called, it loads the pip.conf. We are using artifactory virtual repositories to allow us to pull from both public pip via pip remote and local repositories within artifactory
@shivambats yes, but if you sam build -u (build in Docker), you still have to hardcode your repository credentials. For now you can't pass them as environment variables.
We're facing currently the same issue as @naxxfish at the company: trying to build an application, with python depenencies in CodeArtifact with sam build --use-container. Index configuration within the container is not supported, which blocks developers (using windows) to build apps.
We can't find any cleanish resolution for this issue yet. @sanathkr do you have any plan to implement this feature in the near future?
👍 to @liszi - I'm exploring CodeArtifact for private packages and trying to reconcile local builds using containers with this.
A way to leverage pip.conf would be preferable. Requiring the addition of --extra-index-url in every requirements.txt file less so, but I will test it.
@timbedard the auth tokens can go up to 12 hours so not too concerned there. More an issue of guidance to my devs on reusing tokens and not grabbing new ones every time.
At runtime, we would call the docker (or finch) CLI, like docker buildx --secret id=demo,src=./secret.txt .... At this point it works the same as any other docker build secret.
Edit: Sorry for closing the issue, I did not mean to close it because this doesn't solve it for ZIP functions.
Activity
jackarailo commentedon Jul 1, 2020
Hi @jfuss just wanted to check whether you have any recent updates on this? My use case is slightly different as I have private github repos so I'd need to pass in a github token (or ssh key) and build within the container. This is essentially the same to the question I've found on stack overflow here
theholy7 commentedon Jul 15, 2020
Any updates on this issue? How have people installed private packages into their lambdas?
carpnick commentedon Oct 4, 2020
This is a direct need to any customers that have private packages. Not sure why this wasnt included in the 1.0 release.
hangingman commentedon Oct 9, 2020
We have the same issue, is there any way to install private python package ?
EDIT
pip install wheelpip config set global.extra-index-url https://${PYPI_USER}:${PYPI_PASS}@mypypi.com/simple/SAM error message is very unfriendly...
carpnick commentedon Oct 9, 2020
We have a workaround. Since SAM is using PIP under the covers. We just generate as part of the build system a pip.conf in the correct directory. When SAM runs, and pip is called, it loads the pip.conf. We are using artifactory virtual repositories to allow us to pull from both public pip via pip remote and local repositories within artifactory
Using a jenkins library:
forzagreen commentedon Dec 1, 2020
Relates to: #2144
shivambatsgit commentedon Dec 14, 2020
Something that worked for us was to have the extra-index-url in the requirements.txt itself
The requirements.txt looks like this
For requirements format and other options
forzagreen commentedon Dec 14, 2020
@shivambats yes, but if you
sam build -u(build in Docker), you still have to hardcode your repository credentials. For now you can't pass them as environment variables.UPDATE:
Now you can, with the parameter
-e, --container-env-var TEXTCf. https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-build.html
nickswiss commentedon Jan 19, 2021
This issue has been open for quite some time. Its seems this is a common enough use case and problem that it should be addressed.
qbedard commentedon Jan 22, 2021
This has been wrecking my day. Guess I'll be hard-coding some URLs for a bit. 😭
naxxfish commentedon May 12, 2021
Also run into this problem. It's extra inconvenient if your private repository has temporary credentials, e.g. CodeArtifact.
liszi commentedon Jun 1, 2021
We're facing currently the same issue as @naxxfish at the company: trying to build an application, with python depenencies in CodeArtifact with
sam build --use-container. Index configuration within the container is not supported, which blocks developers (using windows) to build apps.We can't find any cleanish resolution for this issue yet.
@sanathkr do you have any plan to implement this feature in the near future?
brysontyrrell commentedon Dec 14, 2021
👍 to @liszi - I'm exploring CodeArtifact for private packages and trying to reconcile local builds using containers with this.
A way to leverage
pip.confwould be preferable. Requiring the addition of--extra-index-urlin everyrequirements.txtfile less so, but I will test it.qbedard commentedon Dec 16, 2021
Be warned that it can be a pain in the butt to keep regenerating your token for local development.
brysontyrrell commentedon Dec 16, 2021
@timbedard the auth tokens can go up to 12 hours so not too concerned there. More an issue of guidance to my devs on reusing tokens and not grabbing new ones every time.
mbtx2 commentedon May 24, 2023
This. Please. Not sure why this isn't fully supported, especially with CodeArtifact.
dcabib commentedon Oct 6, 2025
Hi @sanathkr and team,
After thorough analysis of this issue, code review, and practical testing, I'd like to propose closing this issue as resolved. Here's why:
✅ The Core Request Has Been Fully Implemented
Original Request (November 2018):
Solution Implemented (2020):
--container-env-varparameter for passing individual environment variables--container-env-var-fileparameter for loading multiple variables from a JSON fileBoth features are fully functional and tested as of December 2024.
Current Working Solution
Method 1: Inline Environment Variables
Pass environment variables directly via command line:
Or reference from shell environment:
Method 2: Environment Variables File
For multiple variables, use a JSON file:
Create
build-env.json:{ "Parameters": { "PYPI_USER": "myuser", "PYPI_PASS": "mypassword", "PYPI_INDEX_URL": "https://pypi.example.com/simple" } }{"Parameters": {...}}structure shown above.Use in build:
Method 3: Combining Both Methods
You can use both inline and file-based env vars together:
Practical Usage Examples
Example 1: Private PyPi with Basic Authentication
requirements.txt:
Build command:
Example 2: AWS CodeArtifact
Fetch token and build:
requirements.txt:
Example 3: Multiple Private Repositories
build-env.json:
{ "Parameters": { "INTERNAL_PYPI_USER": "user1", "INTERNAL_PYPI_PASS": "pass1", "VENDOR_PYPI_TOKEN": "token2" } }requirements.txt:
reedham-aws commentedon May 13, 2026
This should be possible for some use cases with image functions and secret repositories after #8913. An example template would be like:
and a Dockerfile like
At runtime, we would call the docker (or finch) CLI, like
docker buildx --secret id=demo,src=./secret.txt .... At this point it works the same as any other docker build secret.Edit: Sorry for closing the issue, I did not mean to close it because this doesn't solve it for ZIP functions.