Skip to content

Instantly share code, notes, and snippets.

Embed
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'
_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