DEV Community

Rafaf Tahsin
Rafaf Tahsin

Posted on

Any better way to calculate AWS CodeArtifact Usage?

I needed to know consumed total storage in AWS CodeArtifact. I didn't get this from AWS Console or straight forward aws cli. So I came up with this dirty way ...

#!/bin/bash

export AWS_PROFILE=infolytxdev

domains=$(aws codeartifact list-domains | jq -r ".domains[].name")
total_artifactory_size=0

for d in $domains; do
  repos=$(aws codeartifact list-repositories-in-domain --domain $d | jq -r ".repositories[].name")
  for r in $repos; do
    packages=$(aws codeartifact list-packages --domain $d --repository $r | jq -r ".packages[].package")
    for p in $packages; do
      packageversions=$(aws codeartifact list-package-versions --package $p --domain $d --repository $r --format pypi | jq -r ".versions[].version")

      for pv in $packageversions; do
        sizes=$(aws codeartifact list-package-version-assets --domain $d --repo $r --format pypi --package $p --package-version $pv | jq -r ".assets[].size")
        echo $d" "$p" "$r" "$pv" "$sizes >>size.tb

        total=0

        for size in $sizes; do
          sum=$(($total + $size))
        done

        echo "Package Size: $sum" >>size.tb
        total_artifactory_size=$((total_artifactory_size + $sum))

      done
    done
  done
done

echo "Total Artifactory Size: $total_artifactory_size"
Enter fullscreen mode Exit fullscreen mode

Any better way to accomplish this?

Top comments (2)

Collapse
 
almenon profile image
Almenon •

The storage size is listed in the UI. Go to codeartifact -> domains

Collapse
 
rafaftahsin profile image
Rafaf Tahsin •

Thanks, @almenon .