Skip to content

Instantly share code, notes, and snippets.

@josh-authy
Created June 14, 2016 19:45
Show Gist options
  • Save josh-authy/e27d1a81c607955a03cbbceb1e75e9cf to your computer and use it in GitHub Desktop.
Save josh-authy/e27d1a81c607955a03cbbceb1e75e9cf to your computer and use it in GitHub Desktop.
Get EC2 Information
sudo apt-get install cloud-utils
And then you can:
EC2_INSTANCE_ID=$(ec2metadata --instance-id)
You can get most of the metadata associated with the instance this way:
ec2metadata --help
Syntax: /usr/bin/ec2metadata [options]
Query and display EC2 metadata.
If no options are provided, all options will be displayed
Options:
-h --help show this help
--kernel-id display the kernel id
--ramdisk-id display the ramdisk id
--reservation-id display the reservation id
--ami-id display the ami id
--ami-launch-index display the ami launch index
--ami-manifest-path display the ami manifest path
--ancestor-ami-ids display the ami ancestor id
--product-codes display the ami associated product codes
--availability-zone display the ami placement zone
--instance-id display the instance id
--instance-type display the instance type
--local-hostname display the local hostname
--public-hostname display the public hostname
--local-ipv4 display the local ipv4 ip address
--public-ipv4 display the public ipv4 ip address
--block-device-mapping display the block device id
--security-groups display the security groups
--mac display the instance mac address
--profile display the instance profile
--instance-action display the instance-action
--public-keys display the openssh public keys
--user-data display the user data (not actually metadata)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment