Skip to content

Instantly share code, notes, and snippets.

@mrparkers
Last active April 16, 2021 20:02
Show Gist options
  • Save mrparkers/8a8a28f641ce6462fd75ea118350e18a to your computer and use it in GitHub Desktop.
Save mrparkers/8a8a28f641ce6462fd75ea118350e18a to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
# works with aws-vault v4.6.4
credServerRunning=$(lsof -i tcp:9099 | wc -l | tr -d ' ')
if [[ "${credServerRunning}" != "0" ]]; then
echo "AWS Credential Server already running"
exit 1
fi
function eksInfo() {
printf "Connected to EKS cluster $1 using role $2\n\n"
curl --silent http://localhost:9099/ | jq -C '.'
}
export -f eksInfo
if [ -z "$1" ]; then
read -p "Role: " role
else
role=$1
fi
if [ -z "$2" ]; then
read -p "Cluster name: " name
else
name=$2
fi
if [ -z "$3" ]; then
read -p "Region: " region
else
region=$3
fi
aws-vault exec ${role} -- aws eks update-kubeconfig --name ${name} --region ${region}
aws-vault exec -s ${role} -- tail -f /dev/null &
pid=$(echo $!)
sleep 2
watch -e -t -n 15 --color -x bash -c "eksInfo ${name} ${role}"
kill -9 ${pid}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment