Skip to content

Instantly share code, notes, and snippets.

@bruvio
Created September 27, 2022 08:40
Show Gist options
  • Select an option

  • Save bruvio/93e95cca717b18983dc9c38e3a14a3d7 to your computer and use it in GitHub Desktop.

Select an option

Save bruvio/93e95cca717b18983dc9c38e3a14a3d7 to your computer and use it in GitHub Desktop.
get aws credential from sso and store into profile
aws_cred()
{
local role=${1:-arn:aws:iam::xxxxx:role/yyyyyy}
local rolesessionname=${2:-runner-promotion}
creds_json=$(aws sts assume-role --role-arn ${role} --role-session-name ${rolesessionname})
export AWS_ACCESS_KEY_ID=$(echo "$creds_json" | jq .Credentials.AccessKeyId |tr -d '"')
export AWS_SECRET_ACCESS_KEY=$(echo "$creds_json" | jq .Credentials.SecretAccessKey| tr -d '"')
export AWS_SESSION_TOKEN=$(echo "$creds_json" | jq .Credentials.SessionToken|tr -d '"')
export AWS_REGION=eu-west-2
cp /dev/null ~/.aws/credentials
echo "[ci_deploy]" > ~/.aws/credentials
echo AWS_ACCESS_KEY_ID=$(echo "$creds_json" | jq -r .Credentials.AccessKeyId) >> ~/.aws/credentials
echo AWS_SECRET_ACCESS_KEY=$(echo "$creds_json" | jq -r .Credentials.SecretAccessKey) >> ~/.aws/credentials
echo AWS_SESSION_TOKEN=$(echo "$creds_json" | jq -r .Credentials.SessionToken) >> ~/.aws/credentials
cat ~/.aws/credentials
echo ""
echo $creds_json
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment