简体   繁体   中英

How to use JMESPath to query AWS CLI RDS instances by DBInstanceIdentifier

I need a list of RDS DBInstanceIdentifier that match the String "foobar" in their name. I found many solutions with exact match, but not substring matching. My approach looks as follows:

I get a list of all DBInstanceIdentifier using:

aws rds describe-db-instances --query "DBInstances[*].[DBInstanceIdentifier][]" which looks like

[
    "machine-001-alice-abcdefg", 
    "machine-002-bob-abcdefg", 
    "machine-003-foobar-abcdefg"
]

On the list I apply a filter like in the last example of the JMSES Tutorial

aws rds describe-db-instances --query "DBInstances[*].[DBInstanceIdentifier][]|[?contains(@,'dev') =='true']"

If I change the statement to,= I get the full list. so it seems I have the filter statement wrong.

true needs to be backticked not quoted and then the backticks need to be escaped it seems - different shells may vary.

aws rds describe-db-instances --query "DBInstances[*].[DBInstanceIdentifier][]|[?contains(@,'dev')==\`true\`]"
aws rds describe-db-instances --query "DBInstances[*].[DBInstanceIdentifier][]|[?contains(@,'dev')!=\`true\`]"

You can also omit the comparison to true but I couldn't invert this successfully

aws --profile pollen-nonprod rds describe-db-instances --query "DBInstances[*].[DBInstanceIdentifier][]|[?contains(@,'dev')]"

(I'd normally do this sort of thing with jq but that's a different solution rather than necessarily a better one)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM