Created
May 9, 2023 17:10
-
-
Save shollingsworth/a65099d1a8b7d5bf426af5fbd70de55f to your computer and use it in GitHub Desktop.
Revisions
-
shollingsworth created this gist
May 9, 2023 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ #!/usr/bin/env bash # install yawsso https://github.com/victorskl/yawsso # make sure aws cli is installed # call with `sso` ################################################################################ # when calling these functions make sure AWS_PROFILE is set ################################################################################ SSO_REGION="us-east-2" awswhoami() { out=$(aws sts get-caller-identity | jq .) echo "${out}" arn=$(echo "${out}" | jq -r '.Arn') name=$(echo "${arn}" | tr '/' ' ' | awk '{print $2}') acctnum=$(echo "${arn}" | tr ':' ' ' | awk '{print $4}') aalias=$(aws iam list-account-aliases | jq ".AccountAliases[0]" -r) # if [[ "*AWSReservedSSO*" "${arn}" ]]; then if echo "${arn}" | grep -q 'AWSReservedSSO'; then out="Role: arn:aws:iam::${acctnum}:role/aws-reserved/sso.amazonaws.com/${SSO_REGION}/${name}" else out="Role: arn:aws:iam::${acctnum}:role/${name}" fi echo "${out}" echo "Account: ${aalias}" } checkawsprofile() { if [[ -z "${AWS_PROFILE}" ]]; then echo "AWS_PROFILE is not set" return 1 fi return 0 } alias yawme="checkawsprofile && yawsso -p ${AWS_PROFILE}" alias sso="checkawsprofile && aws sso login && yawme && awswhoami"