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

2 minute read
0

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.

Resolution

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
image_name="amzn2-ami-kernel-5.10-hvm"
image_version="2"
image_arch="x86_64"
image_file="amzn2-ami-kernel-5.10-hvm-2.0.20230515.0-x86_64.xfs.gpt"
image_stamp="87bd-09e4"
image_date="20230518225829"
recipe_name="amzn2 ami"
recipe_id="2d7a2685-fafa-d212-204a-4ea2-2fd4-593c-8d69c8af"

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 http://169.254.169.254/latest/dynamic/instance-identity/document/ | grep imageId | awk -F'"' '/imageId/ { print $4 }')
    
    $ REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document/ | 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
    amzn2-ami-kernel-5.10-hvm-2.0.20230515.0-x86_64-gp2

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 OFFICIAL
AWS OFFICIALUpdated 7 months ago