Search code examples
aws-clijmespath

Find all values between X and Y in JMESpath


I'm trying to query aws logs in the AWS cli. The query I tried aws logs describe-log-streams --log-group-name /aws/batch/job --region us-west-1 --order-by LastEventTime

The reply I get starts like:

{  
   "logStreams":[  
      {  
         "logStreamName":"Name-With-Identifier",
         "creationTime":1549558015102,
         "firstEventTimestamp":1549558015498,
         "lastEventTimestamp":1549558028386,
         "lastIngestionTime":1549558028565,
         "uploadSequenceToken":"49590579609731080948197832029410897711804458425099756082",
         "arn":"arn:aws...",
         "storedBytes":2311
      },
      {  
         "logStreamName":"Name-With-Identifier",
         "creationTime":1549558037404,
         "firstEventTimestamp":1549558037788,
         "lastEventTimestamp":1549558054875,
         "lastIngestionTime":1549558055107,
         "uploadSequenceToken":"49588831790141890077331969472298852407397478833047221858",
         "arn":"arn:aws...",
         "storedBytes":12702
      },
      {  
         "logStreamName":"Name-With-Identifier",
         "creationTime":1566839792673,
         "firstEventTimestamp":1566839793320,
         "lastEventTimestamp":1566839793964,
         "lastIngestionTime":1566839931587,
         "uploadSequenceToken":"49595380751905665182286741430582817999725054738015728770",
         "arn":"arn:aws...",
         "storedBytes":0
      }
   ]
}

I am only interested in logs where the firstEventTimestamp is between 1566594000 and 1566853200. Is there a way to do that, and if so how? I couldn't find an answer at http://jmespath.org/tutorial.html.

BTW, please ignore the time discrepancy, that can be solved (either automatically or by playing with the --starting-token option).


Solution

  • If you don't use dynamics value and just want the logs between 1566594000 and 1566853200 here's the request:

    logStreams[?firstEventTimestamp >= `1566594000` && firstEventTimestamp <= `1566853200`]