Skip to content

Instantly share code, notes, and snippets.

@nl5887
Created October 26, 2014 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nl5887/0f74155e2ea36b0fb3bb to your computer and use it in GitHub Desktop.
Save nl5887/0f74155e2ea36b0fb3bb to your computer and use it in GitHub Desktop.
Shows metadata about the current cloud instance. For use in logon scripts or prompts.
#!/bin/sh
# http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
instanceid=`curl http://169.254.169.254/latest/meta-data/instance-id -s`
amiid=`curl http://169.254.169.254/latest/meta-data/ami-id -s`
hostname=`curl http://169.254.169.254/latest/meta-data/hostname -s`
instancetype=`curl http://169.254.169.254/latest/meta-data/instance-type -s`
kernelid=`curl http://169.254.169.254/latest/meta-data/kernel-id -s`
securitygroups=`curl http://169.254.169.254/latest/meta-data/security-groups -s`
publichostname=`curl http://169.254.169.254/latest/meta-data/public-hostname -s`
availabilityzone=`curl http://169.254.169.254/latest/meta-data/placement/availability-zone -s`
userdata=`curl http://169.254.169.254/latest/user-data -s -f`
echo "
===============================================================================================
# Instance-id: $instanceid
# AMI-id: $amiid
#
# Public: $publichostname
# Private: $hostname
#
# Availability zone: $availabilityzone
# Instance type: $instancetype
#
# Security groups:
# $securitygroups
================================================================================================
$userdata
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment