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
In addition to passing the options directly in the sam build command line, pip has a couple of ways of storing the information so you don't have to explicitly pass it in via each command line:
Config file
The pypi user and password can be stored in a config file in some specific locations (e.g. $HOME/.config/pip/pip.conf). You could look to see if any of the supported pip config files are present, and mount them into the docker container.
Environment Variables
You can now use environment variables within a requirements.txt with pip 10+.
With this I can now run sam build and it will use my private pypi as long as I have those environment variables available. This doesn't work when building using a container as you can not pass in environment variables.
Reacted by David Twamley, benDavidson6, Wael, Nick Tallant, khwaja Jawad Ahmed and Fabien Bousquet
@billyshambrook I wonder if we just pass system env vars into the container instead? I have had this conversation with @sthulb about the Go builders some time back. I am not sure why we don't pass the env vars into the container already (maybe some security reason?) but I think it makes sense for build to pass the system env vars into the container by default.
We did not pass environment variables to provide isolation. When you build inside the container, the environment is not tainted by configuration you have set in your terminal. However, I think it is a good idea to pass through standard environment variables used by package managers.
@billyshambrook Do you know which env vars are standard to Python Packaging (Twine, PyPi) etc?
We could make a change to automatically pass those through, if available.
So we would have to keep a mapping of what each package manager to "standard" environment variables? That sounds like more configuration we have to keep track of and another point for customers to get confused by ("I can build locally but not in the container"). I don't see why we can't pass the system env vars. I don't agree that it taints the configuration. I should be able to define env vars to configure things in the container or locally.
Yes, it is another set of configs to maintain, but in reasonable time we will get good coverage of the standard envvars.
I think we should set clear expectations of building locally vs container. This where the confusion is. Based on how we define we could go one way or the other
It’s too constraining. If we don’t want to mount system env vars, we should at least provide a way for customers to configure.
Keeping this mapping does not scale. Provided runtimes, plugin builders, etc. I am strongly against having SAM CLI maintain and updating what env vars map to what container. It’s just another “X introduced Y” that we have to keep track of.
We'd like to pass --ignore-installed pip flag to sam build --use-container and it doesn't work.
docker-env
$ sam build --use-container --docker-env PYP_IGNORE_INSTALLED=true
Usage: sam build [OPTIONS] [FUNCTION_IDENTIFIER]
Try "sam build --help" for help.
Error: no such option: --docker-env
requirements.txt file
file:
--ignore-installed
pyathena==1.7.1
Output:
$ sam build --use-container
Starting Build inside a container
Unable to process properties of PredictFunction.AWS::Serverless::Function
Building resource 'InitPredictFunction'
Fetching lambci/lambda:build-python3.6 Docker container image......
Mounting /Users/rinat/Developer/Projects/Basking/bs-data/aws_cfn/ds_model/application as /tmp/samcli/source:ro,delegated inside runtime container
Build Failed
Running PythonPipBuilder:ResolveDependencies
Error: PythonPipBuilder:ResolveDependencies - Usage: -c [options]
ERROR: Invalid requirement: --ignore-installed
-c: error: no such option: --ignore-installed
Is there any workaround or another approach to pass these settings to pip in sam?
Is there any more work on this? We are facing a similar problem where we want to include private repos into our requirements.txt file but would need to hardcode user and passwords into the file to get them.
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
billyshambrook commentedon Dec 29, 2018
In addition to passing the options directly in the sam build command line, pip has a couple of ways of storing the information so you don't have to explicitly pass it in via each command line:
Config file
The pypi user and password can be stored in a config file in some specific locations (e.g.
$HOME/.config/pip/pip.conf). You could look to see if any of the supported pip config files are present, and mount them into the docker container.Environment Variables
You can now use environment variables within a requirements.txt with pip 10+.
This could allow you to do something like...
With this I can now run
sam buildand it will use my private pypi as long as I have those environment variables available. This doesn't work when building using a container as you can not pass in environment variables.billyshambrook commentedon Apr 12, 2019
@sanathkr you reckon we could add an additional argument to the build command to pass in environment variables to the build container?
sam build --use-container --docker-env PYPI_USER=123,PYPI_PASS=xxxShould be fairly easy to hook up as the BuildContainer uses Container class which already allows env vars to be passed in.
Thanks!
jfuss commentedon Apr 12, 2019
@billyshambrook I wonder if we just pass system env vars into the container instead? I have had this conversation with @sthulb about the Go builders some time back. I am not sure why we don't pass the env vars into the container already (maybe some security reason?) but I think it makes sense for build to pass the system env vars into the container by default.
Here is the code where we made the decision right now: https://github.com/awslabs/aws-sam-cli/blob/develop/samcli/local/docker/lambda_build_container.py#L87
@sanathkr Thoughts?
sanathkr commentedon Apr 15, 2019
We did not pass environment variables to provide isolation. When you build inside the container, the environment is not tainted by configuration you have set in your terminal. However, I think it is a good idea to pass through standard environment variables used by package managers.
@billyshambrook Do you know which env vars are standard to Python Packaging (Twine, PyPi) etc?
We could make a change to automatically pass those through, if available.
jfuss commentedon Apr 15, 2019
So we would have to keep a mapping of what each package manager to "standard" environment variables? That sounds like more configuration we have to keep track of and another point for customers to get confused by ("I can build locally but not in the container"). I don't see why we can't pass the system env vars. I don't agree that it taints the configuration. I should be able to define env vars to configure things in the container or locally.
sanathkr commentedon Apr 15, 2019
Yes, it is another set of configs to maintain, but in reasonable time we will get good coverage of the standard envvars.
I think we should set clear expectations of building locally vs container. This where the confusion is. Based on how we define we could go one way or the other
jfuss commentedon Apr 15, 2019
It’s too constraining. If we don’t want to mount system env vars, we should at least provide a way for customers to configure.
Keeping this mapping does not scale. Provided runtimes, plugin builders, etc. I am strongly against having SAM CLI maintain and updating what env vars map to what container. It’s just another “X introduced Y” that we have to keep track of.
ltrojana3d commentedon May 28, 2019
@jfuss @sanathkr
I had the same issue with env vars and setting specific build parameters for the pip install (CFLAGS, etc)
would not make sense something like it was suggested above by @billyshambrook
--docker-env MYVAR=myval?rinatio commentedon Sep 13, 2019
We'd like to pass
--ignore-installedpip flag tosam build --use-containerand it doesn't work.file:
Output:
Is there any workaround or another approach to pass these settings to pip in
sam?benDavidson6 commentedon May 11, 2020
Is there any more work on this? We are facing a similar problem where we want to include private repos into our requirements.txt file but would need to hardcode user and passwords into the file to get them.
11 remaining items
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.