Getting the Centos8 AMI ID from AWS cli - the free one

Posted on Sat 21 November 2020 in Computing

The Centos8 AMI published by Amazon is not actually free. However, the image that it is based on from the Centos team is.

Have a look at https://wiki.centos.org/Cloud/AWS

To get the free one published by the Centos team, you can use:

aws --region eu-west-1 ec2 describe-images --owners 125523088429 \
    --filters Name=architecture,Values='arm64' Name=name,Values='CentOS 8.*'

(Note this is getting the arm64 one, not the x86_64 image)

If you want something a bit sexier - in this case processed with JQ so that I can use it with packer, this might help:

aws ec2 describe-images \
    --owners 125523088429 \
    --filters Name=architecture,Values='arm64' Name=name,Values='CentOS 8.*' \
    | jq '.Images | sort_by(.CreationDate) | last(.[]) | {"aws_centos_latest": .ImageId}'