Skip to content

Instantly share code, notes, and snippets.

@evilmarty
Created December 9, 2021 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evilmarty/f100035fe8ad57efb5460002eab0ce83 to your computer and use it in GitHub Desktop.
Save evilmarty/f100035fe8ad57efb5460002eab0ce83 to your computer and use it in GitHub Desktop.
Check if your AWS SSO session is still valid and if not prompt a message
AWS_SSO_CACHE="${HOME}/.aws/sso/cache"
check_aws_sso_session() {
local files=()
if [ -d "$AWS_SSO_CACHE" ]; then
local files=("${AWS_SSO_CACHE}/*.json")
fi
for file in ${files[@]}; do
valid_cache "$file" && return 0
done
/bin/cat <<EOT
AWS SSO session expired. Run the following to renew your session:
aws sso login
EOT
}
valid_cache() {
case "$1" in
*botocore-client-id*)
return 1
;;
*)
/usr/local/bin/jq '.expiresAt | fromdate | if . > now then halt else halt_error end' "$1" 2>/dev/null
;;
esac
}
check_aws_sso_session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment