Syntax for filters for aws rds describe-db-instances
Asked Answered
G

2

6

When we run the command using filters we are getting the error:

$ aws rds describe-db-instances --filters Name=instance-state-name,Values=running

An error occurred (InvalidParameterValue) when calling the
DescribeDBInstances operation: Unrecognized filter name: instance-state-name.

What is the correct syntax for using filters for aws rds describe-db-instances?

Gillett answered 5/9, 2017 at 9:28 Comment(0)
K
10

Your syntax seems to be fine, but instance-state-name is simply not a valid filter for RDS.

From the documentation:

--filters (list)

A filter that specifies one or more DB instances to describe.

Supported filters:

    db-cluster-id - Accepts DB cluster identifiers and DB cluster Ama-
    zon Resource Names (ARNs). The results list will only include
    information about the DB instances associated with the DB Clusters
    identified by these ARNs.

    db-instance-id - Accepts DB instance identifiers and DB instance
    Amazon Resource Names (ARNs). The results list will only include
    information about the DB instances identified by these ARNs.

As something like instance-state-name doesn't exist for RDS I assume what you're searching for instead is DBInstanceStatus. While it's not possible to use --filter to filter for that, you can use --query:

aws rds describe-db-instances --query 'DBInstances[?DBInstanceStatus==`available`]'

The difference between --filter and --query is that --filter directly influences what's sent back by the API, while --query does some local filtering of the results received from the API. As long as you don't have a very large amount of RDS instances, --query should work fine for you.

Kimon answered 5/9, 2017 at 9:54 Comment(4)
HI if there any way to filter the output fields .aws rds describe-db-instances --query "DBInstances[?DBInstanceIdentifier==xyz]" --query "DBInstances[*].[DBInstanceArn,Engine,DBInstanceIdentifier,EngineVersion,Address]"Gillett
Yes, you can use the --query option for that as well. Check out the documentation: docs.aws.amazon.com/cli/latest/userguide/…Kimon
Specify --query only once, like: aws rds describe-db-instances --query "DBInstances[?DBInstanceIdentifier==xyz].[DBInstanceArn,Engine,DBInstanceIdentifier,E‌​ngineVersion,Address‌​]"Kimon
Is there any way to get the header information when we try to get the output in table format. C:\Program Files\Amazon\AWSCLI>aws rds describe-db-instances --query "DBInstances[*].[Engine,DBInstanceIdentifier,EngineVersion,Endpoint.Address,AllocatedStorage,DBInstanceClass,Endpoint.Port]"Gillett
D
0

Adding quotes should work

example:

aws rds describe-db-cluster-endpoints --db-cluster-identifier=aurora-cluster-dev  --query 'DBClusterEndpoints[*].[Endpoint]' --filters 'Name=db-cluster-endpoint-type,Values=writer'
Droit answered 3/2, 2023 at 18:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.