Using pip
1. Authenticating using AWS CLI
Make sure AWS CLI has set with an account in the o-akodnm2nsf
org id. (ECS org).
aws codeartifact login --tool pip --repository npm --domain neev --domain-owner 529730085565 --region 'eu-west-2'
caution
The token is valid for 12 hours by default. You'll need to call this command again to get a new token.
info
This will update ~/.config/pip/pip.conf
(%APPDATA%\pip\pip.ini
on Windows) to set the index-url to the repository specified by the --repository option.
This causes all (including PyPI) packages to be fetched from our code repository which will work as a mirror of PyPI.
2. Manually set PIP config
You can get the token using AWS CLI command and then use it to set PIP index URL.
Set CODEARTIFACT_AUTH_TOKEN
environment variable with the authentication token generated using AWS CLI.
- macOS or Linux
- Powershell
export CODEARTIFACT_AUTH_TOKEN=`aws codeartifact get-authorization-token --domain neev --domain-owner 529730085565 --query authorizationToken --output text --region eu-west-2`
$env:CODEARTIFACT_AUTH_TOKEN = aws codeartifact get-authorization-token --domain neev --domain-owner 529730085565 --query authorizationToken --output text --region eu-west-2
More details on getting the authorization token.
tip
If you get "An error occurred (ResourceNotFoundException) when calling the GetAuthorizationToken operation: Domain not found. Domain 'neev' owned by account '529730085565' does not exist."
Then make sure the aws cli has been set with an account in the o-akodnm2nsf
org id. (ECS org).
caution
The token is valid for 12 hours by default. You'll need to call this command again to get a new token.
pip config set global.index-url https://aws:$CODEARTIFACT_AUTH_TOKEN@my_domain-111122223333.d.codeartifact.region.amazonaws.com/pypi/my_repo/simple/
If you need to setup private index just for the virtual environment for one project, you have to create a pip.ini (Windows) or pip.conf file in the root of your virtual environment directory (Replace <token>
with authentication token).
[global]
# other properties
# ...
index-url = https://aws:<token>@neev-529730085565.d.codeartifact.eu-west-2.amazonaws.com/pypi/pypi/simple/
note
If you already have a pip configuration file in your virtual environment root, you can use the pip config
command to set index-url (see above example), instead of manually editing the configuration file.
caution
Do not confuse virtual environment root with project root.
3. Using extra package index
If you want to use public PyPI respository as your primary index and want to use neev as secondary (Or vise versa), you can use extra-index-url configuration available in pip. Configure index-url with your primary index and extra-index-url with neev index.
Example pip.conf with neev as secondary index.
[global]
# other properties
# ...
index-url = https://pypi.org/simple
extra-index-url = https://aws:<token>@neev-529730085565.d.codeartifact.eu-west-2.amazonaws.com/pypi/pypi/simple/
caution
Be aware about potential dependency confusion vulnerability when using extra-index-url. An attacker can publish a package in public index with the same name as that of a private package.
4. Installing packages
If you have already setup index-url or extra-index-url in pip config file, you can simply install the package with following command.
pip install example-package-math
You can also download packages by specifying index-url or extra-index-url while using pip command.
pip install example-package-math --index-url https://aws:<token>@neev-529730085565.d.codeartifact.eu-west-2.amazonaws.com/pypi/pypi/simple/
# or
pip install example-package-math --extra-index-url https://aws:<token>@neev-529730085565.d.codeartifact.eu-west-2.amazonaws.com/pypi/pypi/simple/
# or
pip install -r requirements.txt --extra-index-url https://aws:<token>@neev-529730085565.d.codeartifact.eu-west-2.amazonaws.com/pypi/pypi/simple/
You can also set the index url in requirements.txt with credential replaceable by environment variable.
--extra-index-url https://aws:${CODEARTIFACT_AUTH_TOKEN}@neev-529730085565.d.codeartifact.eu-west-2.amazonaws.com/pypi/pypi/simple/
example-package-math==0.1.9
pytz