Little project to explore pushing and pulling a Python libray to AWS Code Artifact.
- Install pyenv
- Install Poetry
- Install AWS CLI V2
# Clone project
$ git clone https://github.com/mel-cdn/aws-code-artifact-python.git
$ cd aws-code-artifact-python
# Setup Python environment
$ pyenv install 3.12.3
$ poetry env use python3.12
$ poetry shell
$ poetry env info
$ poetry install
# Test Python environment
$ pytest --cov=shared
-
Create a domain if you don't have one yet. For console or CLI guide, see details here.
-
Create a repository under the domain. For console or CLI guide, see details here.
-
Add this policy to your AWS account or service account to be able to interact (publish and pull) with the repository.
All steps below requires your AWS profile to be configured already on your CLI.
# domain-owner = AWS Account ID
# Retrieve CodeArtifact authorization token...
$ AUTH_TOKEN=$(
aws codeartifact get-authorization-token \
--domain-owner "1234567890123" \
--domain "mello-world" \
--query 'authorizationToken' \
--output text
)
# Retrieve CodeArtifact repository URL...
$ CODE_ARTIFACT_REPO_URL=$(
aws codeartifact get-repository-endpoint \
--domain-owner "1234567890123" \
--domain "mello-world" \
--repository "aws-code-artifact-python" \
--format pypi \
--query 'repositoryEndpoint' \
--output text
)
$ echo "$CODE_ARTIFACT_REPO_URL"
# Build Python package
$ poetry build
Building aws-code-artifact-python (0.0.1)
- Building sdist
- Built aws_code_artifact_python-0.0.1.tar.gz
- Building wheel
- Built aws_code_artifact_python-0.0.1-py3-none-any.whl
# Publish to CodeArtifact repository
$ poetry config repositories.python-demo "$CODE_ARTIFACT_REPO_URL"
$ poetry config http-basic.python-demo aws "$AUTH_TOKEN"
Using a plaintext file to store credentials
$ poetry publish -r python-demo
Publishing aws-code-artifact-python (0.0.1) to demo-python
- Uploading aws_code_artifact_python-0.0.1-py3-none-any.whl 100%
- Uploading aws_code_artifact_python-0.0.1.tar.gz 100%
# Install module
$ aws codeartifact login \
--tool pip \
--domain-owner "1234567890123" \
--domain "mello-world" \
--repository "aws-code-artifact-python" \
--profile "default" \
--region "ap-southeast-1"
Login expires in 12 hours at 2024-09-24 09:25:24+08:00
$ pip install aws-code-artifact-python
# Show installed modules
$ pip list
Package Version Editable project location
------------------------ --------- ----------------------------------
aws-code-artifact-python 0.0.1 /c/projects/aws-code-artifact-python
# Reset to default source of pypi packages
$ pip config unset global.index-url