Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CLI --query to select tag by value

There were a lot of topics about this, but I still have a problem with a query.

I used:

aws rds list-tags-for-resource --resource-name arn:aws:rds:eu-west-:xxxxx --query 'TagList[*]'

Output:

{

    "Value": "test@test",
    "Key": "Owner"
},
{
    "Value": "XXXX",
    "Key": "Schedule"
}   

I need to display only XXXX value. I tried:

aws rds list-tags-for-resource --resource-name arn:aws:rds:eu-west-1:xxxxx --query 'TagList[].Tags[?Key==`Schedule`].Value[]' --output text

but it does not work.

like image 845
KamilK Avatar asked Nov 15 '25 20:11

KamilK


2 Answers

Give a try to this:

aws rds list-tags-for-resource --resource-name arn:aws:rds:eu-west-:xxxxx --query "TagList[?Key=='Schedule'].Value[]"

Also, you may want to use jq:

aws rds list-tags-for-resource --resource-name arn:aws:rds: | jq ".TagList[].Value"
like image 96
nbari Avatar answered Nov 18 '25 13:11

nbari


You do not have a nested Tags key inside the TagList list. Filter at the same level:

aws rds list-tags-for-resource \
--resource-name your:arn \
--query 'TagList[?Key==`Schedule`]'
like image 25
hjpotter92 Avatar answered Nov 18 '25 11:11

hjpotter92



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!