From 764b2b2e3900aa58cf3460ab8e601075d35f3fc1 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Tue, 29 Apr 2025 22:40:03 +0200 Subject: [PATCH] chore(jmespath): add some list operations --- knowledge base/jmespath.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/knowledge base/jmespath.md b/knowledge base/jmespath.md index 66ba17f..42e47da 100644 --- a/knowledge base/jmespath.md +++ b/knowledge base/jmespath.md @@ -33,6 +33,23 @@ az disk-encryption-set show --ids 'id' \ \"keyId\": activeKey.keyUrl, \"accessPolicyId\": join('/', [activeKey.sourceVault.id, 'objectId', identity.principalId]) }" + +# Sort elements in a list. +# Refer . +# Ascending. Use `reverse(sort_by(…))` to get the list in descending order. +# Refer . +aws ec2 describe-images --filters 'Name=tag:Name,Values=[RunnerBaseline]' \ + --query 'sort_by(Images, &LastLaunchedTime)[]' + +# Slice arrays. +# Refer . +aws ec2 describe-images … --query 'Images[]' # all elements +aws ec2 describe-images … --query 'Images[3:]' # elements from 4th onwards +aws ec2 describe-images … --query 'Images[:6]' # elements from 1st to 5th +aws ec2 describe-images … --query 'Images[1:4]' # elements from 2nd to 5th +aws ec2 describe-images … --query 'Images[5:9:2]' # odd elements from 5th to 9th +aws ec2 describe-images … --query 'Images[-3:]' # the last 3 elements +aws ec2 describe-images … --query 'Images[::-1]' # all elements in reverse order ``` ## Further readings