Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --url flag to ec2-metadata to override metadata-server #39

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions ec2-metadata
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ Options:
-s/--security-groups Names of the security groups the instance is launched in. Only available if supplied at instance launch time
-d/--user-data User-supplied data.Only available if supplied at instance launch time.
-g/--tags Tags assigned to this instance.
--quiet Suppress tag keys from the output."
--quiet Suppress tag keys from the output.
--url Override base URL for metadata server (default http://169.254.169.254)"
}

METADATA_BASEURL="http://169.254.169.254"
Expand Down Expand Up @@ -156,9 +157,6 @@ function print_all()
print_tags
}

#check if run inside an EC2 instance
set_imds_token

#command called in default mode
if [ "$#" -eq 0 ]; then
print_all
Expand All @@ -169,7 +167,7 @@ shortopts=almnbithokzPcpvuresdgR
longopts=(ami-id ami-launch-index ami-manifest-path ancestor-ami-ids block-device-mapping
instance-id instance-type local-hostname local-ipv4 kernel-id availability-zone
partition product-codes public-hostname public-ipv4 public-keys ramdisk-id
reservation-id security-groups user-data tags region help all quiet)
reservation-id security-groups user-data tags region help all quiet url:)

oldIFS="$IFS"
IFS=,
Expand All @@ -192,6 +190,10 @@ while true; do
--quiet)
QUIET=1 ; shift
;;
--url)
shift
METADATA_BASEURL=$1; shift
;;
--)
shift ; break
;;
Expand All @@ -207,6 +209,9 @@ while true; do
esac
done

#check if run inside an EC2 instance
set_imds_token

#start processing command line arguments
for action in "${actions[@]}"; do
case "$action" in
Expand Down