If you work with AWS daily (devops, cloud engineer, etc), especially if you manage more than one account, you’re likely familiar with the hassle of switching profiles in the AWS CLI. I’ve been there myself. I once had a critical moment on a project where I almost provisioned infrastructure to the wrong environment. The cause was simple: I forgot to switch the active AWS credential.
That incident got me thinking, “There has to be a more efficient way to switch profiles.” After conducting some research, I finally found the solution, which turned out to be in a tool I already use every day: Oh My Zsh.

This feature completely changed my workflow, making the process of switching accounts incredibly fast and safe. Today, I want to share this practical guide with you.
Before we dive into the configuration, make sure you have these two tools installed on your computer:
All set? Let’s get started!
To make the magic happen, we need to tell Oh My Zsh to enable its AWS plugin. Often, this plugin is not enabled by default.
It’s very easy to set up:
# Example .zshrc content
plugins=(git aws)
4. Save the file, then reload your terminal configuration by running:
source ~/.zshrc
Now for the most important part. The AWS CLI stores all your account configurations in a folder named ~/.aws. Inside, there are two key files we need to set up: credentials and config.
Think of this file as a secure wallet for your secret access keys. It stores the aws_access_key_id and aws_secret_access_key for each account.
IMPORTANT: Because this file contains sensitive data, never share its contents with anyone!
Open the ~/.aws/credentials file and set it up like the example below. Each account is separated by a [profile-name].
[default]
aws_access_key_id = AKIAIOSFODNN7EXAMPLE
aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
[project-a]
aws_access_key_id = AKIAI44QH8DHBEXAMPLE
aws_secret_access_key = je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY
[project-b-sandbox]
aws_access_key_id = AKIA3IT55L4A4EXAMPLE
aws_secret_access_key = 5i/raJx4ottp8kZTu16j6TGN2iLoEXAMPLEKEY
This file is used to store non-sensitive settings, such as the default region or output format for each profile. The format is similar to the credentials file, but the profile name is prefixed with the word profile.
Open the ~/.aws/config file and align it with the profiles you created earlier.
[default]
region = ap-southeast-1
output = json
[profile project-a]
region = us-east-1
output = json
[profile project-b-sandbox]
region = ap-southeast-3
output = text
Once everything is configured, the Oh My Zsh aws plugin provides several helpful aliases (command shortcuts). These commands work by setting the AWS_PROFILE environment variable for your terminal session.
asp (AWS Set Profile)
This is your main command for switching profiles.
$ asp <press Tab>
default project-a
$ asp project-a
AWS profile set to 'project-a'
agp (AWS Get Profile)
This command is useful for checking which profile is currently active.
$ agp
project-
unset-aws-profile
If you want to return to the default profile or simply deactivate the current one, use this command.
$ unset-aws-profile
AWS profile unset
With these three simple commands, switching between AWS accounts becomes incredibly fast and safe. Say goodbye to the risk of deploying to the wrong environment!
Happy coding, and I hope this tip makes your workflow more efficient!