使用 jmespath 按日期排序
Sort by date with jmespath
json 输出如:
{
"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"
}
]
}
如何return 按 LastModified 排序的两个最近的函数?
您需要先使用 reverse
和 sort_by
。然后为两条记录添加 [:2]
:
aws lambda list-functions --query "reverse(sort_by(Functions, &LastModified))[:2]"
如果需要top 1 last modified,其名称以'abc'
开头
--query "reverse(sort_by([?starts_with(name, 'abc')], &properties.lastModified))[:1]"
json 输出如:
{
"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"
}
]
}
如何return 按 LastModified 排序的两个最近的函数?
您需要先使用 reverse
和 sort_by
。然后为两条记录添加 [:2]
:
aws lambda list-functions --query "reverse(sort_by(Functions, &LastModified))[:2]"
如果需要top 1 last modified,其名称以'abc'
开头--query "reverse(sort_by([?starts_with(name, 'abc')], &properties.lastModified))[:1]"