Search code examples
amazon-web-servicespython-poetryaws-codeartifact

AWS Codeartifact and Poetry auth problems with private packages


I have big problems problems when i are trying to add my private package e.g.

poetry add my-package

My source inside my pyproject.toml file is like this

[[tool.poetry.source]]
name = "aws"
url = "{repo-url}"
priority = "primary"

The problem I get every time is 401 Client Error: Unauthorized for URL:, and I can't fix it unless I use basic authentication in the URL like this.

url = "https://aws:[email protected]"

I don't want to commit my token directly to my project for safety, and I have not tried the CLI whiteout with any luck.

How did it work, did i use it in a wrong way?


Solution

  • How I fixed it is before I use poetry update, I will run.

    poetry config http-basic.aws aws $(aws codeartifact get-authorization-token --domain-owner {account-id} --domain {domain} --query 'authorizationToken' --output text)

    After that, I can update or install my packages as I want; remember, the token will expire, and then you need to prepare this command to connect to the code artifact again.

    i did not found a way around it, this works fine for me.