Skip to content

Commit 220d932

Browse files
committed
Allow region discovery
1 parent 2939e0f commit 220d932

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

doc/ec2-metadata.8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ The ID of the kernel launched with this instance, if applicable.
8686
.B \-z/\-\-availability-zone
8787
The availability zone in which the instance launched. Same as placement
8888
.TP
89+
.B \-R/\-\-region
90+
The region in which the instance launched.
91+
.TP
8992
.B \-c/\-\-product-codes
9093
Product codes associated with this instance.
9194
.TP

ec2-metadata

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
function print_help()
1010
{
11-
echo "ec2-metadata v0.1.2
11+
echo "ec2-metadata v0.1.3
1212
Use to retrieve EC2 instance metadata from within a running EC2 instance.
1313
e.g. to retrieve instance id: ec2-metadata -i
1414
to retrieve ami id: ec2-metadata -a
@@ -30,6 +30,7 @@ Options:
3030
-o/--local-ipv4 Public IP address if launched with direct addressing; private IP address if launched with public addressing.
3131
-k/--kernel-id The ID of the kernel launched with this instance, if applicable.
3232
-z/--availability-zone The availability zone in which the instance launched. Same as placement
33+
-R/--region The region in which the instance launched.
3334
-P/--partition The AWS partition name.
3435
-c/--product-codes Product codes associated with this instance.
3536
-p/--public-hostname The public hostname of the instance.
@@ -39,7 +40,8 @@ Options:
3940
-e/--reservation-id ID of the reservation.
4041
-s/--security-groups Names of the security groups the instance is launched in. Only available if supplied at instance launch time
4142
-d/--user-data User-supplied data.Only available if supplied at instance launch time.
42-
-g/--tags Tags assigned to this instance."
43+
-g/--tags Tags assigned to this instance.
44+
--quiet Suppress tag keys from the output."
4345
}
4446

4547
METADATA_BASEURL="http://169.254.169.254"
@@ -141,6 +143,7 @@ function print_all()
141143
print_normal_metric local-ipv4 meta-data/local-ipv4
142144
print_normal_metric kernel-id meta-data/kernel-id
143145
print_normal_metric placement meta-data/placement/availability-zone
146+
print_normal_metric region meta-data/placement/region
144147
print_normal_metric partition meta-data/services/partition
145148
print_normal_metric product-codes meta-data/product-codes
146149
print_normal_metric public-hostname meta-data/public-hostname
@@ -162,11 +165,11 @@ if [ "$#" -eq 0 ]; then
162165
fi
163166

164167
declare -a actions
165-
shortopts=almnbithokzPcpvuresdg
168+
shortopts=almnbithokzPcpvuresdgR
166169
longopts=(ami-id ami-launch-index ami-manifest-path ancestor-ami-ids block-device-mapping
167170
instance-id instance-type local-hostname local-ipv4 kernel-id availability-zone
168171
partition product-codes public-hostname public-ipv4 public-keys ramdisk-id
169-
reservation-id security-groups user-data tags help all quiet)
172+
reservation-id security-groups user-data tags region help all quiet)
170173

171174
oldIFS="$IFS"
172175
IFS=,
@@ -218,6 +221,7 @@ for action in "${actions[@]}"; do
218221
-o | --local-ipv4 ) print_normal_metric local-ipv4 meta-data/local-ipv4 ;;
219222
-k | --kernel-id ) print_normal_metric kernel-id meta-data/kernel-id ;;
220223
-z | --availability-zone ) print_normal_metric placement meta-data/placement/availability-zone ;;
224+
-R | --region ) print_normal_metric region meta-data/placement/region ;;
221225
-P | --partition ) print_normal_metric partition meta-data/services/partition ;;
222226
-c | --product-codes ) print_normal_metric product-codes meta-data/product-codes ;;
223227
-p | --public-hostname ) print_normal_metric public-hostname meta-data/public-hostname ;;

0 commit comments

Comments
 (0)