AWS-CLI Profile Management Made Easy

AWS-CLI profile management on your local desktop can be a hassle. Especially if you frequently switch between different accounts. Keeping track of available profiles, switching between them and knowing which one you’re using at the time is tedious. Setting up named profiles helps a little bit but it doesn’t take you all the way. I personally don’t like the –profile argument, I’m too lazy to use that.

I set out to come to terms with this and came up with three aliases that I can use in my shell. They allow me to list available profiles, view the current profile configuration and switch to another profile.

First of all, you have to configure the aws-cli with named profiles. If you haven’t done so, the aws-cli documentation will guide you through this in a few easy steps.
Once you have your profiles configured we can move on to the next step; setting up the aliases.

Create the aliases

This code snippet contains a couple of functions that we will invoke with the new aliases.
Create a new file and paste the code snippet below, hit Ctrl+C to exit.

cat > ~/._awsAliases

Now open ~/.bash_profile in your favourite editor and add the following lines:

List available profiles

To see a list of all available profiles, type:

awsall

Switch profile

To switch to another profile, type:

awsp profilename

Show the current profile

The aws-cli actually provides a command for listing the current profile configuration (aws configure list). I find it a bit long to type so I added an alias for this too:

awswho

And that’s it. I hope this will help you manage your aws-cli profiles as much as it has helped me. Happy clouding!

PS. Don’t use Access Keys in your production account. That’s bad form ;)

6 Comments

  1. Addemdum:
    It turns out that, at least the Javascript SDK, does not adhere to AWS_DEFAULT_PROFILE but expects an environment variable named AWS_PROFILE.
    The script above has been updated and now sets both these variables.

  2. Yet another addendum:

    The SDKs (or at least the Javascript SDK) does not pick up the region from the profile configuration.The script above has been updated and now sets the AWS_REGION environment variable to the same region as your profile points to.

  3. Andrei Neculau

    credentialFileLocation=$(env | grep AWS_SHARED_CREDENTIALS_FILE | cut -d= -f2);
    as a “shortcut” for
    credentialFileLocation=${AWS_SHARED_CREDENTIALS_FILE}

    ? :)

  4. Any chance you can put this up on GitHub or similar so folks can PR against it?

  5. Ive been looking for a simple widget to let me quickly configure my AWS CLI profile. No need to look any further.

Trackbacks for this post

  1. AWS-CLI Profile Management Made Easy – Jayway | Ausfestivus's Blog

Leave a Reply