AWS Codebuild - List all projects and output into a file.
Zeke Sebulino
Posted on March 6, 2023
Hey there! So, I recently had to tackle the challenge of identifying all of our AWS CodeBuilds that were using soon-to-be-deprecated Linux images. Given the large number of builds in our project, manually sifting through each one would have taken forever.
To save time, I turned to the AWS CLI and crafted a command that would help me list out all of our CodeBuilds alongside their corresponding Linux images. This way, I could quickly identify the builds that needed updating.
Here's the command I used:
aws codebuild list-projects | jq '.projects[]' | xargs -I{} sh -c 'aws codebuild batch-get-projects --names "$1" | jq -r "\"\(.projects[].name) : \(.projects[].environment.image)\"" ' _ {} >> list.txt
It's a bit of a mouthful, but essentially what it does is use the list-projects command to fetch all CodeBuild projects, pipe them to jq to extract the project names, and then use xargs to pass each project name to the batch-get-projects command, which fetches the full project details including the Linux image. Finally, I used jq again to format the output as "project name : Linux image", and wrote the results to a file called list.txt.
Hope this helps you save some time too!
Posted on March 6, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.