Skip to content

ajishab/switch-aws

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

AWS EKS Switcher

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

Prerequisites

  1. AWS CLI installed

    brew install awscli
  2. 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

  1. kubectl installed
    brew install kubectl

Installation

  1. Clone this repository or download the switch-aws.sh file

  2. Add the following line to your ~/.zshrc or ~/.bashrc file:

    source /path/to/switch-aws.sh
  3. Reload your shell configuration:

    source ~/.zshrc  # or source ~/.bashrc

Usage

Basic Usage

switch-aws <aws-profile-name>

This will:

  1. Check if you have a valid AWS SSO session and prompt for login if needed
  2. Set your AWS_PROFILE environment variable
  3. Update your kubeconfig for the EKS cluster with the same name as the profile

Specifying a Different Cluster Name

switch-aws <aws-profile-name> <eks-cluster-name>

Use this when your EKS cluster name is different from your AWS profile name.

Listing Available Profiles

switch-aws --list
# or
switch-aws -l

Lists all available AWS profiles from your ~/.aws/config file.

Skip Kubernetes Configuration

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.

Examples

# 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

Features

  • Automatic AWS SSO session management
  • Environment variable configuration
  • kubeconfig updates for EKS clusters
  • Error handling with descriptive messages

Troubleshooting

If you encounter issues:

  1. Ensure your AWS config file is properly configured
  2. Check that you have the necessary permissions to access the specified EKS clusters
  3. Verify your network connection for AWS SSO authentication

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages