配置和使用麻线 CodeArtifact - CodeArtifact

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

配置和使用麻线 CodeArtifact

twine 是一款适用于 Python 程序包的程序包发布实用程序。要使用 twine 将 Python 包发布到 CodeArtifact 仓库,必须先使用仓 CodeArtifact 库信息和凭据配置 twine。

twine 只能用于发布 Python 程序包。要安装 Python 程序包,您可以使用 pip。有关更多信息,请参阅 配置并使用 pip CodeArtifact

使用 login 命令配置 twine

首先,配置您的 AWS 凭证以与一起使用 AWS CLI,如中所述开始使用 CodeArtifact。然后,使用 CodeArtifactlogin命令获取凭据并使用它们配置 twine。

注意

如果您要访问您拥有的域中的存储库,则无需包括 --domain-owner。有关更多信息,请参阅 跨账户域

要配置 twine,请运行以下命令。

aws codeartifact login --tool twine --domain my_domain --domain-owner 111122223333 --repository my_repo

login CodeArtifact 使用您的 AWS 凭证获取授权令牌。该login命令将 twine 配置为 CodeArtifact 通过编辑~/.pypirc添加--repository选项指定的带有凭据的存储库来使用。

调用 login 后的默认授权期为 12 小时,且必须调用 login 来定期刷新令牌。有关使用 login 命令创建的授权令牌的更多信息,请参阅 使用 login 命令创建的令牌

不使用 login 命令配置 twine

如果无法使用 login 命令来配置 twine,则可以使用 ~/.pypirc 文件或环境变量。要使用 ~/.pypirc 文件,请在文件添加以下条目。密码必须是获得的身份验证令牌。get-authorization-token API

[distutils] index-servers = codeartifact [codeartifact] repository = https://my_domain-111122223333.d.codeartifact.us-west-2.amazonaws.com/pypi/my_repo/ password = auth-token username = aws
注意

要使用双堆栈端点,请使用该codeartifact.region.on.aws端点。

要使用环境变量,请执行以下操作:

注意

如果您要访问您拥有的域中的存储库,则无需包括 --domain-owner。有关更多信息,请参阅 跨账户域

export TWINE_USERNAME=aws export TWINE_PASSWORD=`aws codeartifact get-authorization-token --domain my_domain --domain-owner 111122223333 --query authorizationToken --output text` export TWINE_REPOSITORY_URL=`aws codeartifact get-repository-endpoint --domain my_domain --domain-owner 111122223333 --repository my_repo --format pypi --query repositoryEndpoint --output text`

运行 twine

在使用 twine 发布 Python 包资源之前,必须先配置 CodeArtifact 权限和资源。

  1. 按照设置为 AWS CodeArtifact部分中的步骤配置您的 AWS 账户、工具和权限。

  2. 按照 使用 login 命令配置 twine不使用 login 命令配置 twine 中的步骤配置 twine。

配置 twine 之后,就可以运行 twine 命令。使用以下命令来发布 Python 程序包资产。

twine upload --repository codeartifact mypackage-1.0.tgz

有关如何构建和打包 Python 应用程序的信息,请参阅 Python 打包权威机构网站上的生成分发存档