Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
bash-fu to set AWS instance metadata as environment variables
#!/bin/bash -x
_JQ_FILTER='.ds | .dynamic | .["instance-identity"] | .document'
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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment