0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

uvにてAWS CodeArtifactのPythonパッケージをインストールする

Last updated at Posted at 2025-02-18

CodeArtifactでホストしているPythonのパッケージをuvでインストールする方法についてです。

まず、以下の公式のドキュメントにも方法がいくつか記載があります。こちらも確認してみてください。

上記のドキュメントに記載が無い方法を書こうと思います。

index毎の認証を環境変数で渡す方法について

pyproject.toml にて以下のようにCodeArtifactの情報を設定を準備します。

この設定に対して認証情報を渡します。

[[tool.uv.index]]
name = "myartifact"
url = "https://my-domain-012345678912.d.codeartifact.ap-northeast-1.amazonaws.com/pypi/my-repository/simple"

この時点だとCodeArtifactの認証が通らずにエラーとなります。

$ uv add my-package
Using CPython 3.12.9
Creating virtual environment at: .venv
  × No solution found when resolving dependencies:
  ╰─▶ Because my-package was not found in the package registry and your project depends on my-package, we can conclude that your project's requirements are unsatisfiable.

      hint: An index URL (https://my-domain-012345678912.d.codeartifact.ap-northeast-1.amazonaws.com/pypi/my-repository/simple) could not be queried due to a lack of valid
      authentication credentials (401 Unauthorized).
  help: If you want to add the package regardless of the failed resolution, provide the `--frozen` flag to skip locking and syncing.

以下のように UV_INDEX_ 始まりの環境変数から認証情報を渡せるようになります。

# Tokenを取得します
AWS_CODEARTIFACT_TOKEN="$(
    aws codeartifact get-authorization-token \
    --domain $AWS_DOMAIN \
    --domain-owner $AWS_ACCOUNT_ID \
    --query authorizationToken \
    --output text
)"


# 以下の形式で認証情報を設定
# UV_INDEX_{tomlファイルのtool.uv.index.nameを大文字}_USERNAME=aws
# UV_INDEX_{tomlファイルのtool.uv.index.nameを大文字}_PASSWORD=${token}
export UV_INDEX_MYARTIFACT_USERNAME=aws
export UV_INDEX_MYARTIFACT_PASSWORD=${AWS_CODEARTIFACT_TOKEN}


# これでインストール可能です
uv add my-package
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?