A CLI for AWS CodeArtifact - The Missing Tool for Your Python Packages
An introduction to py-aws-code-artifact-tool, a command-line tool that simplifies building, configuring, and publishing Python packages to AWS CodeArtifact.
AWS CodeArtifact is a fantastic service for managing private Python packages, ensuring your proprietary code remains secure and separate from the public PyPI registry. However, the process of configuring your local environment, building a package, and publishing it can involve a series of manual, and often tricky, AWS CLI commands.
To streamline this workflow, I developed py-aws-code-artifact-tool
, a simple command-line interface that wraps these steps into three easy-to-remember commands.
The Challenge: Manual CodeArtifact Steps
Publishing a Python package to CodeArtifact typically requires you to:
- Log in to the correct AWS account.
- Fetch an authorization token from CodeArtifact.
- Configure
pip
ortwine
to use the CodeArtifact repository URL with the new token. - Build your package (
sdist
andwheel
). - Finally, publish the package using
twine
.
This process is not only tedious but also error-prone. A single misstep, like an expired token or incorrect domain, can lead to frustrating authentication errors.
A Simpler Way: The py-aws-code-artifact-tool
This tool simplifies the entire process into a dedicated CLI with three main commands:
configure
: Sets up your AWS CodeArtifact credentials.build
: Builds your Python package insdist
andwheel
formats.publish
: Publishes the package to your configured CodeArtifact repository.
Step 1: Configure Your Environment
First, run the configure
command. The tool will prompt you for your AWS CodeArtifact domain, repository name, and AWS profile. It then automatically fetches a fresh authorization token and configures your local environment.
aws-code-artifact configure
Step 2: Build Your Package
Next, navigate to your Python project's root directory and run the build
command. This command simply runs python setup.py sdist bdist_wheel
to generate your distribution files.
aws-code-artifact build
Step 3: Publish to CodeArtifact
Finally, run the publish
command. The tool uses the credentials from the configure
step to upload your newly built package to your private repository.
aws-code-artifact publish
And that's it. Your package is now securely hosted in AWS CodeArtifact, ready to be installed in your other projects.
Getting Started
py-aws-code-artifact-tool
is available as an open-source project. To get started, clone the repository and install it from the source.
# Clone the repository
git clone https://github.com/geekcafe/py-aws-code-artifact-tool.git
# Install the tool
cd py-aws-code-artifact-tool
pip install .
Conclusion
py-aws-code-artifact-tool
was built to solve a common pain point for Python developers working with AWS. By simplifying the authentication and publishing process, it saves time and reduces the friction of using a private package repository.
Check out the project on GitHub, and I welcome any feedback or contributions to make it even better.