Skip to content

Instantly share code, notes, and snippets.

@arigesher
Created January 30, 2020 19: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 arigesher/1b7c86482fa1d20da904c6ec9498d8a2 to your computer and use it in GitHub Desktop.
Save arigesher/1b7c86482fa1d20da904c6ec9498d8a2 to your computer and use it in GitHub Desktop.
bash-fu to set AWS instance metadata as environment variables
#!/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