2 min read

DevOps Series - Multiple AWS CLI Accounts

Lack of direction, not lack of time, is the problem. We all have twenty-four hour days.

— Zig Ziglar.

As a Dev Ops, I handle multiple project all at once. One problem I encountered is managing multiple AWS accounts for different startups. So how to handle multiple AWS account?

Prerequisites

Before you start doing this, I assume you already know basic command line interface whether its for Windows or from *Nix (Linux, macOS, Unix) derivatives. And also you must have a python interpreter with at least version 3 above.

Multiple, Multiple to the Nth

First, if you haven’t got the AWS CLI (Command Line Interface) install it using the command pip install --upgrade --user awscli. The command will install the awscli package in your local python dist directory.

And now we begin.

You’ll need to generate first your AWS keys and secret access key. Here are the steps.

  • Go to IAM Console
  • Go to Users in the navigation pane and select your IAM username.
  • Select Security credentials and choose Create access key.

Then, after that we will need to configure our AWS using aws configure --profile <your-profile-name>.

aws configure --profile my-profile-name

This command will need some more input from you like your AWS Key, AWS Secret, AWS Account Region and the default output format which would be JSON or TEXT.

If everything is setup properly, we will proceed with running a some sample commands. Also in order for you to use the configured AWS profile, you must always append at the end of your AWS command the --profile <your-profile-name>.

aws configure --profile my-profile-name

Or if you can and will be using it always, export an environment variable AWS_PROFILE containing the profile name like export AWS_PROFILE=<your-profile-name>.

export AWS_PROFILE=my-profile-name

And cheers, you can now use multiple credentials through AWS CLI.

Conclusion

Hi guys a quick tip from me: sometimes, having multiple projects can cause headaches. So as a reminder, always focus and finish one project first before you move to other projects. Stay tuned for more blog updates and series.