A helper shell function that simplifies switching between AWS profiles and EKS clusters.
When you do a switch it will:
- Validate IAM Identity Center Authentication and ReAuthenticate if Needed
- Switch AWS PROFILE
- Update EKS Context
-
AWS CLI installed
brew install awscli
-
AWS SSO configured in your
~/.aws/config
file. Example configuration:[sso-session my-sso] sso_start_url = https://your-sso-portal.awsapps.com/start sso_region = us-east-1 sso_registration_scopes = sso:account:access [profile dev] sso_session = my-sso sso_account_id = 123456789012 sso_role_name = Developer region = us-east-1 output = json [profile prod] sso_session = my-sso sso_account_id = 987654321098 sso_role_name = Administrator region = us-east-1 output = json
This is great article if you want to learn more about this: https://medium.com/@mrethers/boss-way-to-authenticate-aws-cli-with-sso-for-multi-account-orgs-aa8a5e228bdd
kubectl
installedbrew install kubectl
-
Clone this repository or download the
switch-aws.sh
file -
Add the following line to your
~/.zshrc
or~/.bashrc
file:source /path/to/switch-aws.sh
-
Reload your shell configuration:
source ~/.zshrc # or source ~/.bashrc
switch-aws <aws-profile-name>
This will:
- Check if you have a valid AWS SSO session and prompt for login if needed
- Set your
AWS_PROFILE
environment variable - Update your kubeconfig for the EKS cluster with the same name as the profile
switch-aws <aws-profile-name> <eks-cluster-name>
Use this when your EKS cluster name is different from your AWS profile name.
switch-aws --list
# or
switch-aws -l
Lists all available AWS profiles from your ~/.aws/config
file.
switch-aws <aws-profile-name> --no-k8s
Only sets the AWS profile without updating the Kubernetes configuration. Useful when you just need to switch AWS contexts without working with EKS.
# Switch to the dev profile and dev cluster
switch-aws dev
# Switch to the prod profile and prod-cluster-v2 cluster
switch-aws prod prod-cluster-v2
- Automatic AWS SSO session management
- Environment variable configuration
- kubeconfig updates for EKS clusters
- Error handling with descriptive messages
If you encounter issues:
- Ensure your AWS config file is properly configured
- Check that you have the necessary permissions to access the specified EKS clusters
- Verify your network connection for AWS SSO authentication