Created
January 30, 2020 19:47
-
-
Save arigesher/1b7c86482fa1d20da904c6ec9498d8a2 to your computer and use it in GitHub Desktop.
bash-fu to set AWS instance metadata as environment variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -x | |
_JQ_FILTER='.ds | .dynamic | .["instance-identity"] | .document' | |
_INSTANCE_DATA=/var/run/cloud-init/instance-data.json | |
export _instance_doc=$(jq "$_JQ_FILTER" $_INSTANCE_DATA) | |
for key in $(echo $_instance_doc | jq -r 'keys|.[]'); do | |
value=$(echo $_instance_doc | jq -r .$key) | |
declare -x _AWS_${key^^}=${value} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment