12

I'm trying to filter by multiple values however I can't seem to get an and clause to work (e.g. filter1 and filter 2 ... etc.):

Show me snapshots where the database name is 'testing'

aws rds describe-db-snapshots --include-shared --query 'DBSnapshots[?DBInstanceIdentifier==`testing`].{DBNAME:DBInstanceIdentifier,SNAPSHOT:DBSnapshotIdentifier}'
[
    {
        "SNAPSHOT": "test1",
        "DBNAME": "testing"
    },
    {
        "SNAPSHOT": "test2",
        "DBNAME": "testing"
    },
    {
        "SNAPSHOT": "test3",
        "DBNAME": "testing"
    },
    {
        "SNAPSHOT": "test4",
        "DBNAME": "testing"
    }
]

Show me snapshots named 'test1'

$ aws rds describe-db-snapshots --include-shared --query 'DBSnapshots[?DBSnapshotIdentifier==`test1`].{DBNAME:DBInstanceIdentifier,SNAPSHOT:DBSnapshotIdentifier}'
[
    {
        "SNAPSHOT": "test1",
        "DBNAME": "testing"
    },
        {
        "SNAPSHOT": "test1",
        "DBNAME": "testing2"
    }
]

Show me snapshots from the database testing that are named test1

aws rds describe-db-snapshots --include-shared --query 'DBSnapshots[?DBInstanceIdentifier==`testing`][?DBSnapshotIdentifier==`test1`].{DBNAME:DBInstanceIdentifier,SNAPSHOT:DBSnapshotIdentifier}'
[]

How can this be achieved?

Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
bob dylan
  • 1,458
  • 1
  • 14
  • 32

1 Answers1

20

You need to work with the AND expression so something like this will make the trick

$ aws rds describe-db-snapshots --include-shared \
--query 'DBSnapshots[?(DBInstanceIdentifier==`testing` && DBSnapshotIdentifier==`test1`)].{DBNAME:DBInstanceIdentifier,SNAPSHOT:DBSnapshotIdentifier}'
bob dylan
  • 1,458
  • 1
  • 14
  • 32
Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
  • I actually needed the && expression not || to return what I want. The link provided is much better than anything I found. Thanks. My final solution is: aws rds describe-db-snapshots --include-shared --query 'DBSnapshots[?DBInstanceIdentifier==`testing` && DBSnapshotIdentifier==`test1`].{DBNAME:DBInstanceIdentifier,SNAPSHOT:DBSnapshotIdentifier}' I've submitted an edit to your answer to reflect this. Once it gets approved I'll accept your response as answer. – bob dylan Nov 08 '17 at 09:41
  • sorry, I misread the initial question and thought you wanted one or the other , thanks for the edit and the correction – Frederic Henri Nov 08 '17 at 09:49