Filter by RDS tag

0

Hi,
I'm working on a script the requires me to filter by a certain tag within RDS. If I run

for instance in source_instances:
    db_instances = "{0}".format(instance['DBInstanceIdentifier'])
    response = source.list_tags_for_resource(
             ResourceName=instance['DBInstanceArn'])
    print (db_instances)
    print (response)

I'm able to see the tags of each of my RDS instances, including the Environment tag.

If I run

    for instance in source_instances:
        db_instances = "{0}".format(instance['DBInstanceIdentifier'])
        response = source.list_tags_for_resource(
            ResourceName=instance['DBInstanceArn'],
            Filters=[{
                'Name': 'Environment',
                'Values': [
                  'Production', 'production',
               ]
             }])

I get the following error
ClientError: An error occurred (InvalidParameterValue) when calling the ListTagsForResource operation: Unrecognized filter name: Environment
Any pointers would be appreciated.

anxjk
gefragt vor 7 Jahren2563 Aufrufe
2 Antworten
0

hi. after trying this for myself. I got the same result. Went to docs and found this. Appears the SDK has the 'bones' (errors if providing the wrong Key Names (Name,Values), but not fully implemented.
http://boto3.readthedocs.io/en/latest/reference/services/rds.html#RDS.Client.describe_db_instances
(dict) --
This type is not currently supported.
Name (string) -- [REQUIRED]
This parameter is not currently supported.
Values (list) -- [REQUIRED]
This parameter is not currently supported.

response = client.list_tags_for_resource(
            ResourceName='arn:aws:rds:ap-south-1:XXXX:db:deletemedb',
            Filters=[{'Name' : 'Environment', 'Values' : ['Production']}])

print(response)
<snip>
botocore.exceptions.ClientError: An error occurred (InvalidParameterValue) when calling the ListTagsForResource operation: Unrecognized filter name: Environment
</snip>

HTH

Edited by: shallawe on Jul 26, 2017 3:24 AM

beantwortet vor 7 Jahren
0

Thanks for the help and sanity check. After a little more digging, other post mentioned getting the ARN of the snapshot and use list_tags_for_resource to find the Taglist. From there, it could be filtered.

There's probably a little bit of a better way to verify the tag but this does work. Source is the client connection to RDS.

#Gets the tags of the snapshot based on the snapshot ARN
        tagresponse = source.list_tags_for_resource(ResourceName=source_snap_arn)
        print ("Response", tagresponse)
        taglist = tagresponse['TagList']
        
        #Looks for the Value Production
        for tag in taglist:
            print (tag['Key'], tag['Value'])
            if tag['Value'] == 'Production':
                print ("Found Production Snapshot")
anxjk
beantwortet vor 7 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen