Skip to content

Instantly share code, notes, and snippets.

@amcginlay
Last active December 1, 2021 19:41
Show Gist options
  • Save amcginlay/2a74c428886d91122fa51e0d2b39b47a to your computer and use it in GitHub Desktop.
Save amcginlay/2a74c428886d91122fa51e0d2b39b47a to your computer and use it in GitHub Desktop.
eks-get-token.sh
#!/bin/bash
# inspired by https://www.youtube.com/watch?v=4l4Kuds8O3s
cluster=dev
# grab the k8s api server endpoint and the encoded authentication token
eks_token=$(aws eks get-token --cluster-name ${cluster} | jq .status.token --raw-output)
eks_endpoint=$(aws eks describe-cluster --name ${cluster} | jq .cluster.endpoint --raw-output)
# decode the token to see what's going on under the hood (this patially fails but the essential details are clear)
echo ${eks_token} | cut -d. -f2 | base64 --decode
# send a request to the endpoint which returns a list of methods
curl -k -H "x-k8s-aws-id: ${cluster}" -H "Authorization: Bearer ${eks_token}" ${eks_endpoint}
# hit the /version method
curl -k -H "x-k8s-aws-id: ${cluster}" -H "Authorization: Bearer ${eks_token}" ${eks_endpoint}/version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment