1

I'm trying to do a query that only return to me the repos that was modified in the last one year.

So I'm trying the following command:

aws codecommit list-repositories --query 'repositories[?lastModifiedDate>=`'"$(date --date='1 month ago' +%s.0000000)"'`]' --output text

But when I use it, nothing return. Someone can point me the right way? Thanks!

StuardBr
  • 11
  • 1

1 Answers1

0

Unfortunately it is not possible to use JMESPath query with list-repositorie to get lastModifiedDate because this one returns only two parameters repositoryName and repositoryId

[
    {
        "repositoryName": "test",
        "repositoryId": "aaaaaa-bbbbb-cccc-dddd-aaaaaaaa"
    }
] 

Instead, you can combine both list-repositorie and get-repository in a bash script for example to solve your problem for example:

#!/bin/bash

# Get a list of all repositories in the account
repositories=$(aws codecommit list-repositories --query 'repositories[].repositoryName' --output text)
echo $repositories
# Loop through each repository and get its details
for repo in $repositories
do
  echo "Repository: $repo"
  details=$(aws codecommit get-repository --repository-name $repo --query 'repositoryMetadata.lastModifiedDate' --output text)
  echo $details
done

Sorry I'm not expert in bash, but the idea is here, you have all the elements, you need just to filter by lastModifiedDate to get what you need.

Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
  • Excellent idea! I'm trying to use the same expression to filter the ModifiedDate in the get-repository command, but still receiving nothing: aws codecommit get-repository --repository-name $repo --query 'repositoryMetadata[?lastModifiedDate>`'"$(date --date="1 year ago" +%Y-%m-%dT%T.000000-03:00)"'']' – StuardBr Mar 14 '23 at 13:33