skip to Main Content

I’m new to the AWS CLI and I am trying to build a CSV server inventory of my project’s AWS RDS instances that includes their tags.

I have done so successfully with EC2 instances using this:

aws ec2 describe-isntances
--query 'Reservations[*].Instances[*].[PrivateIpAddress, InstanceType, [Tags[?Key=='Name'.Value] [0][0], [Tags[?Key=='ENV'.Value] [0][0] ]'
--output text | sed -E 's/s+/,/g' >> ec2list.csv

The above command gives me a CSV with the Ip address, instance type, as well as the values of the listed tags.

However, I am currently trying to do so unsuccessfully on RDS instances with this:

aws rds describe-db-isntances
--query 'DBInstances[*].[DBInstanceIdentifier, DBInstanceArn, [Tags[?Key=='Component'.Value] [0][0], [Tags[?Key=='Engine'.Value] [0][0] ]'
--output text | sed -E 's/s+/,/g' >> rdslist.csv

The RDS command only returns the instance arn and identifier but the tag values show up as none even though they definitely do have a value.

What modifications need to be made to my RDS query to show the tag values/is this even possible? Thanks

2

Answers


  1. Chosen as BEST ANSWER

    Realized that tags can be displayed in my original query. It does not use Tags like EC2 instances but TagList. E.g,

    aws rds describe-db-isntances
    --query 'DBInstances[*].[DBInstanceIdentifier, DBInstanceArn, [TagList[?Key=='Component'.Value] [0][0], [TagList[?Key=='Engine'.Value] [0][0] ]'
    --output text | sed -E 's/s+/,/g' >> rdslist.csv
    

  2. Probably you will need one more command https://docs.aws.amazon.com/AmazonRDS/latest/APIReference//API_ListTagsForResource.html.

    You can wrap the 2 scripts in shell script like the below example.

    #!/bin/bash
    ARNS=$(aws rds describe-db-instances --query "DBInstances[].DBInstanceArn" --output text)
    for line in $ARNS; do
        TAGS=$(aws rds list-tags-for-resource --resource-name "$line" --query "TagList[]")
        echo $line $TAGS
    done
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search