Created
August 6, 2023 21:54
-
-
Save htnosm/c3aea46e581d7d296627d1ab2fe74d35 to your computer and use it in GitHub Desktop.
Get the credentials from AWS CloudShell and output to credential file format.
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
#!/usr/bin/env bash | |
# aws-cloudshell-cred.sh | |
# Get the credentials from AWS CloudShell and output to credential file format. | |
CONTAINER_CREDENTIALS=$(curl -sSf -H "Authorization: ${AWS_CONTAINER_AUTHORIZATION_TOKEN}" "${AWS_CONTAINER_CREDENTIALS_FULL_URI}") | |
if [ $? -ne 0 ]; then | |
echo "failed get container credentials." | |
exit 1 | |
fi | |
echo "# Expiration: $(echo "${CONTAINER_CREDENTIALS}" | jq -r .Expiration)" | |
OUTPUT_CRED="/tmp/cred.$(date +'%Y%m%d_%H%M%S')" | |
echo "# <<<<< .aws/credentials" | |
cat <<_EOF | tee "${OUTPUT_CRED}" | |
export AWS_ACCESS_KEY_ID=$(echo "${CONTAINER_CREDENTIALS}" | jq -r .AccessKeyId) | |
export AWS_SECRET_ACCESS_KEY=$(echo "${CONTAINER_CREDENTIALS}" | jq -r .SecretAccessKey) | |
export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION} | |
export AWS_REGION=${AWS_REGION} | |
export AWS_SECURITY_TOKEN=$(echo "${CONTAINER_CREDENTIALS}" | jq -r .Token) | |
_EOF | |
echo "# >>>>> .aws/credentials" | |
echo "# -----" | |
echo "# Output: ${OUTPUT_CRED}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment