'AWS Profile on command line prompt

A common prompt for the command line is the following:

username@host:~$ Here goes your command

With oh-my-zsh you can tune the command line with the current git branch and more tuning options and having a prompt like this:

~/my-awesome-repo (main) Here goes your command

I work with multiple AWS accounts and sometimes bypassing the --profile parameter with the wrong profile can lead to big problems and even bigger if I forget the parameter, for that reason I change the AWS_PROFILE environment variable each time I need to switch accounts.

I want to know if there is an optimal option in oh-my-zsh with a theme/plugin/configuration that can change my prompt to include the current default AWS_PROFILE environment variable and having something like this:

my-aws-profile ~ Here goes your command

I tried modifying my current theme (zsh2000) adding a function that parse the output of aws configure list with awk but it was extremelly slow since it executes the function for every command and it could take 2-4 seconds, so I want to know if there is a more optimal solution for that.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source