43

In AWS I need to add amazon linux instance to domain based on this article. However how do i know which Amazon Linux version the instance is using. I do not have access to AWS console. But i do have access to actual instance. What linux command i should be using.

I use uname -srm command which returns Linux 4.4.0-1057-aws x86_64

Not sure if this is Amazon Linux 1 or Amazon Linux 2

LP13
  • 30,567
  • 53
  • 217
  • 400

5 Answers5

76

You can use /etc/os-release file to get the info about Amazon Linux Version, the machine is running.

  1. In case of Amazon 1

    [ec2-user@ip-x-x-x- ~]$ cat /etc/os-release
    NAME="Amazon Linux AMI"
    VERSION="2018.03"
    ID="amzn"
    ID_LIKE="rhel fedora"
    VERSION_ID="2018.03"
    PRETTY_NAME="Amazon Linux AMI 2018.03"
    ANSI_COLOR="0;33"
    CPE_NAME="cpe:/o:amazon:linux:2018.03:ga"
    HOME_URL="http://aws.amazon.com/amazon-linux-ami/"
    
  2. In case of Amazon 2

    [ec2-user@x-x-x-x ~]$ cat /etc/system-release
    Amazon Linux release 2.0 (2017.12) LTS Release Candidate
    [ec2-user@fresh-amazon-host ~]$ cat /etc/os-release
    NAME="Amazon Linux"
    VERSION="2.0 (2017.12)"
    ID="amzn"
    ID_LIKE="centos rhel fedora"
    VERSION_ID="2.0"
    PRETTY_NAME="Amazon Linux 2.0 (2017.12) LTS Release Candidate"
    ANSI_COLOR="0;33"
    CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2.0"
    HOME_URL="https://amazonlinux.com/"
    

As you can clearly see the two different versions, mentioned as Amazon Linux and Amazon Linux 2.0

Hardeep Singh
  • 1,314
  • 1
  • 13
  • 15
13
$ cat /etc/system-release

or

$ cat /etc/issue

or

$ uname -a

and head for https://aws.amazon.com/amazon-linux-ami/

Remigiusz
  • 450
  • 3
  • 8
4

Here's a one-liner.

awk -F '[="]*' '/^PRETTY_NAME/ { print $2 }' < /etc/os-release 

It prints out:

Amazon Linux 2
Jameson
  • 6,400
  • 6
  • 32
  • 53
3

You can use the following command:

rpm -E %{rhel} 

For Operating System: Amazon Linux 2

The answer is : 7

Vardit
  • 1,056
  • 2
  • 9
  • 20
Hakimeh Mordadi
  • 181
  • 1
  • 16
2

Well, the announcement in: https://aws.amazon.com/about-aws/whats-new/2017/12/introducing-amazon-linux-2 states that it uses a 4.9 kernel. Yours is older, so I would say it is Linux 1.

Still, the following call from the terminal should give you the AMI ID and you could do a search on that(see docs at https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html):

curl http://169.254.169.254/latest/meta-data/ami-id
Moreno
  • 526
  • 2
  • 14
  • Just know that the AMI ID may not tell you anything. If the instance was created off of a custom AMI then it may not even exist anymore. – JeffR Jun 21 '19 at 19:34