Search code examples
bashamazon-web-servicesaws-cli

Using output of an aws cli command as an input for another command


I have been trying to use output of the list-backup-plans to use as input for get-backup-plan --backup-plan-id. I tried this command but it seems inappropriate for multiple backup plan ids. Could someone address me what correct command can be used?

aws backup list-backup-plans --query BackupPlansList[*].BackupPlanId | xargs -I {} aws backup get-backup-plan --backup-plan-id {}

Solution

  • Make sure to specify the --output option, and replace tabs with newlines:

    aws backup list-backup-plans --query 'BackupPlansList[*].BackupPlanId' --output text | tr "\t" "\n" | xargs -I {} aws backup get-backup-plan --backup-plan-id {}