How do I find the Amazon Linux 2 release version on my running EC2 instance?

2 minute read

I want to find the Amazon Linux 2 release version for my Amazon Elastic Compute Cloud instance.

Short description

Amazon Linux 2 releases have different package versions and CVEs patched. It's important to know what version is on your instance to determine if updates to the Amazon Machine Image (AMI) for your environment are needed.


Use the /etc/image-id file

Each image contains a unique /etc/image-id file. This file includes the name of the image, the image's architecture, recipe name, recipe id, and so on. The image_file field contains the Amazon Linux 2 release version. In the following example, the release version is 2.0.20230515.0.

Example /etc/image-id file

$ cat /etc/image-id
recipe_name="amzn2 ami"

Use the AMI name

If you don't have access to the /etc/image-id file, then use the default image ID to determine the release version.

Note: To use this method, you must have access to the instance metadata. And, you must have permission to run the ec2:DescribeImages command from the assigned AWS Identify and Access Management (IAM) user or role.

  1. Run the following command to get the image ID and the AWS Region for the instance from the instance metadata:

    $ IMAGE_ID=$(curl -s | grep imageId | awk -F'"' '/imageId/ { print $4 }')
    $ REGION=$(curl -s | grep region | awk -F'"' '/region/ { print $4 }')
  2. Run the DescribeImages API command to get the IMAGE_ID. The following example shows the AWS Command Line Interface (AWS CLI) command and output:

    $ aws ec2 describe-images --image-ids $IMAGE_ID --region $REGION --query 'Images[*].Name' --output text

Note: If you receive errors when you run AWS CLI commands, see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.

AWS OFFICIALUpdated 5 months ago