-
-
Save hflamboauto1/d944a8562ebf8340125e3c437cef4322 to your computer and use it in GitHub Desktop.
AWS EC2 extract IAM role data from HTTP instance data using bash & curl.
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 | |
IAM_BASE_URL="http://169.254.169.254/latest/meta-data/iam/security-credentials" | |
IAMRoleName=$(curl -s $IAM_BASE_URL/) | |
IAMRoleData=$(curl -s $IAM_BASE_URL/$IAMRoleName/) | |
IAMRoleAccessKeyID=$(echo -n "$IAMRoleData" | sed -nr 's/.*?"AccessKeyId"[^"]+"([^"]+)",?/\1/p') | |
IAMRoleAccessKeySecret=$(echo -n "$IAMRoleData" | sed -nr 's/.*?"SecretAccessKey"[^"]+"([^"]+)",?/\1/p') | |
IAMRoleToken=$(echo -n "$IAMRoleData" | sed -nr 's/.*?"Token"[^"]+"([^"]+)",?/\1/p') | |
echo $IAMRoleAccessKeyID | |
echo $IAMRoleAccessKeySecret | |
echo $IAMRoleToken |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment