Get the AWS EC2 instance metadata
Thu, Jul 21, 2016Get the AWS EC2 instance metadata
Now you are ready to send the first commands to your EC2 linux instance. Let’s check the EC2 instance metadata by hitting a specific AWS node only available from within the instance itself.
Instance metadata is data about your instance that you can use to configure or manage the running instance. You can list all instance metadata by issuing the following command:
curl -w “\n” http://169.254.169.254/latest/meta-data/
You can easily check the list of security groups attached to the instance, its ID, the hostname, or the ID of the used AMI. These commands are extremely useful when you want to automate the setup of new instances:
curl -w “\n” http://169.254.169.254/latest/meta-data/security-groups
curl -w “\n” http://169.254.169.254/latest/meta-data/ami-id
curl -w “\n” http://169.254.169.254/latest/meta-data/hostname
curl -w “\n” http://169.254.169.254/latest/meta-data/instance-id
curl -w “\n” http://169.254.169.254/latest/meta-data/instance-type
Finally, you can also get the public key of the attached Keypair using the public-keys metadata:
curl -w “\n” http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key