Skip to content

Commit 512c72c

Browse files
committed
add ec2-metadata tags support.
1 parent bb9e1fb commit 512c72c

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

ec2-metadata

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ Options:
3737
-r/--ramdisk-id The ID of the RAM disk launched with this instance, if applicable.
3838
-e/--reservation-id ID of the reservation.
3939
-s/--security-groups Names of the security groups the instance is launched in. Only available if supplied at instance launch time
40-
-d/--user-data User-supplied data.Only available if supplied at instance launch time."
40+
-d/--user-data User-supplied data.Only available if supplied at instance launch time.
41+
-g/--tags Tags assigned to this instance."
4142
}
4243

4344
METADATA_BASEURL="http://169.254.169.254"
@@ -108,6 +109,20 @@ function print_public-keys()
108109
fi
109110
}
110111

112+
#print tags
113+
function print_tags()
114+
{
115+
echo 'tags: '
116+
x=$(get_meta meta-data/tags/instance/)
117+
if [ -n "${x}" ]; then
118+
for i in $x; do
119+
echo -e '\t' $i: $(get_meta meta-data/tags/instance/$i)
120+
done
121+
else
122+
echo not available
123+
fi
124+
}
125+
111126
function print_all()
112127
{
113128
print_normal_metric ami-id meta-data/ami-id
@@ -129,6 +144,7 @@ function print_all()
129144
print_normal_metric reservation-id /meta-data/reservation-id
130145
print_normal_metric security-groups meta-data/security-groups
131146
print_normal_metric user-data user-data
147+
print_tags
132148
}
133149

134150
#check if run inside an EC2 instance
@@ -180,6 +196,8 @@ while [ "$1" != "" ]; do
180196
;;
181197
-d | --user-data ) print_normal_metric user-data user-data
182198
;;
199+
-g | --tags ) print_tags
200+
;;
183201
-h | --help ) print_help
184202
exit
185203
;;

0 commit comments

Comments
 (0)