refresher on jq

jq is an awesome tool for parsing JSON. Today I was searching for an AMI via the aws cli and was able to get a bunch of JSON back from:

aws ec2 describe-images \
    --region us-west-2 \
    --filters "Name=name,Values=amazon-eks-node-1.16*"

I was looking for the most recent release and noticed that the CreationDate in the AMI listings was not sorted. No biggie, right? We’ll just break out jq for some quick cleanup.

aws ec2 describe-images \
    --region us-west-2 \
    --filters "Name=name,Values=amazon-eks-node-1.16*" \
| jq '.Images|=sort_by(.CreationDate)'

Okay now we have the AMI listings in JSON sorted by CreationDate, but there’s an awful lot of info to sift through still.

I decided to just grab the Name and Description fields to make it easier to see the differences between these AMIs:

aws ec2 describe-images \
    --region us-west-2 
    --filters "Name=name,Values=amazon-eks-node-1.16*" \
| jq '.Images|=sort_by(.CreationDate)|.Images[]|.Name,.Description'

and by tacking on the |.Name,.Description to the end of the jq expression, we’re now filtering out the info I needed!

"amazon-eks-node-1.16-v20200423"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.8, docker:18.09.9ce-2.amzn2)"
"amazon-eks-node-1.16-v20200507"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.8, docker:18.09.9ce-2.amzn2)"
"amazon-eks-node-1.16-v20200531"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.8, docker:18.09.9ce-2.amzn2)"
"amazon-eks-node-1.16-v20200609"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.8, docker:19.03.6ce-4.amzn2)"
"amazon-eks-node-1.16-v20200618"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.8, docker:19.03.6ce-4.amzn2)"
"amazon-eks-node-1.16-v20200709"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.12, docker:19.03.6ce-4.amzn2)"
"amazon-eks-node-1.16-v20200710"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.12, docker:19.03.6ce-4.amzn2)"
"amazon-eks-node-1.16-v20200723"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.13, docker:19.03.6ce-4.amzn2)"
"amazon-eks-node-1.16-v20200814"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.13, docker:19.03.6ce-4.amzn2)"
"amazon-eks-node-1.16-v20200821"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.13, docker:19.03.6ce-4.amzn2)"
"amazon-eks-node-1.16-v20200904"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.13, docker:19.03.6ce-4.amzn2)"
"amazon-eks-node-1.16-v20200921"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.13, docker:19.03.6ce-4.amzn2)"
"amazon-eks-node-1.16-v20201002"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.13, docker:19.03.6ce-4.amzn2)"
"amazon-eks-node-1.16-v20201007"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.13, docker:19.03.6ce-4.amzn2)"
"amazon-eks-node-1.16-v20201112"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.15, docker:19.03.6ce-4.amzn2)"
"amazon-eks-node-1.16-v20201117"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.15, docker:19.03.6ce-4.amzn2)"
"amazon-eks-node-1.16-v20201126"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.15, docker:19.03.6ce-4.amzn2)"
"amazon-eks-node-1.16-v20201211"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.15, docker: 19.03.6ce-4.amzn2, containerd: 1.4.1-2.amzn2)"
"amazon-eks-node-1.16-v20210112"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.15, docker: 19.03.6ce-4.amzn2, containerd: 1.4.1-2.amzn2)"
"amazon-eks-node-1.16-v20210125"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.15, docker: 19.03.6ce-4.amzn2, containerd: 1.4.1-2.amzn2)"
"amazon-eks-node-1.16-v20210208"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.15, docker: 19.03.6ce-4.amzn2, containerd: 1.4.1-2.amzn2)"
"amazon-eks-node-1.16-v20210302"
"EKS Kubernetes Worker AMI with AmazonLinux2 image, (k8s: 1.16.15, docker: 19.03.13ce-1.amzn2, containerd: 1.4.1-2.amzn2)"

Leave a Reply