Sort by date with jmespath

隐身守侯 提交于 2019-12-23 08:11:32

问题


With a json output like :

{
   "Functions":[
      {
         "CodeSha256":"7NBvXXacp9x3aK3cKaI=",
         "FunctionName":"function_1",
         "FunctionArn":"arn:aws:lambda:eu-west-1:1111:function:function_1",
         "LastModified":"2015-02-09T11:35:31.084+0000"
      },
      {
         "CodeSha256":"7NBvXXacKaI=",
         "FunctionName":"function_3",
         "FunctionArn":"arn:aws:lambda:eu-west-1:1111:function:function_3",
         "LastModified":"2015-03-09T11:35:31.084+0000"
      },
      {
         "CodeSha256":"7NBvXXacaK3cKaI=",
         "FunctionName":"function_2",
         "FunctionArn":"arn:aws:lambda:eu-west-1:1111:function:function_2",
         "LastModified":"2015-02-11T11:35:31.084+0000"
      }
   ]
}

How can I return the two most recent Functions sorted by LastModified?


回答1:


You need to use reverse and sort_by first. Then add [:2] for only two record :

aws lambda list-functions --query "reverse(sort_by(Functions, &LastModified))[:2]"



回答2:


If you need top 1 last modified, whose name starts with 'abc'

--query "reverse(sort_by([?starts_with(name, 'abc')], &properties.lastModified))[:1]"


来源:https://stackoverflow.com/questions/42414156/sort-by-date-with-jmespath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!