Do you guys know if we can display the EC2 instance type using command line?
Currently, I only have access to the command line of an EC2 instance. Is there a command line that I can type to display the type of instance. eg, p2.8xLarge
or g.16x
etc.
Yes - you can use the meta-data
endpoint to retrieve information about your EC2 instance type via the command line. This command will work if you are using IMDS v1:
> curl http://169.254.169.254/latest/meta-data/instance-type
t1.micro
But note that IMDS v2 is now the default! Running the above command on an instance that only allows v2 will result in "401 - Unauthorized".
See this page for more information about the available commands.
If interacting with IMDS v2, you would issue these commands instead:
TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`
curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/instance-type