Forked from dclark/aws-cloud-shell-get-aws-credentials.sh
Created
March 23, 2025 06:05
-
-
Save vsujeesh/a11581800863e5e70c3147ad23bf629c to your computer and use it in GitHub Desktop.
AWS CloudShell get credentials
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 | |
| # Retrieve AWS credentials from AWS CloudShell | |
| # shellcheck disable=SC2001 | |
| HOST=$(echo "$AWS_CONTAINER_CREDENTIALS_FULL_URI" | sed 's|/latest.*||') | |
| TOKEN=$(curl -s -X PUT "$HOST"/latest/api/token -H "X-aws-ec2-metadata-token-ttl-seconds: 60") | |
| OUTPUT=$(curl -s "$HOST/latest/meta-data/container/security-credentials" -H "X-aws-ec2-metadata-token: $TOKEN") | |
| echo "export AWS_ACCESS_KEY_ID=$(echo "$OUTPUT" | jq -r '.AccessKeyId')" | |
| echo "export AWS_SECRET_ACCESS_KEY=$(echo "$OUTPUT" | jq -r '.SecretAccessKey')" | |
| echo "export AWS_SESSION_TOKEN=$(echo "$OUTPUT" | jq -r '.Token')" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment