#!/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"