Using multiple IAM profiles through AWS CLI

Amazon Web Services

We have several different environments hosted in different Amazon accounts so need to create IAM accounts for each. So switching between different IAM accounts is very useful. The AWS CLI allows you to store different profiles. If you haven’t installed the CLI already, then follow Amazon’s guide here.

Configuring Multiple Accounts:

When you configure your AWS CLI tool, a configuration file gets created at ~/.aws/config in Linux/Unix or in Windows at C:\Users\USERNAME\.aws\config , which looks like:

This has a default profile , that gets created when you run “ aws configure “

To create this profile enter:

Default output format can be either json, text, or table. If you don’t specify an output format, json will be used.

Now to create multiple profiles ,  run the following which will append to your aws configuration file ( ~/.aws/config ) :

Now when you want to use this different profile for a simple command you use the profile parameter -profile

If you want to switch to use a profile  for mutiple commands enter:


Linux, macOS or Unix

Setting the environment variable changes the default profile until the end of your shell session, or until you set the variable to a different value.


No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Amazon Web Services
Copy All files from an S3 Bucket to your PC

This powershell script copies the contents of an S3 bucket to your pc. # Your account access key – must have read access to your S3 Bucket $accessKey = “YOUR-ACCESS-KEY” # Your account secret access key $secretKey = “YOUR-SECRET-KEY” # The region associated with your bucket e.g. eu-west-1, us-east-1 etc. …

Amazon Web Services
Common AWS EC2 CLI commands

The AWS GUI console is a basic way to manage AWS EC2 instances. If you are performing repetitive tasks on multiple instances then using the CLI is a better way to manage. All these commands assume you have the necessary permissions to run. This is some more common CLI examples: …

Amazon Web Services
How to Increase the Size of an AWS EBS Cloud Volume attached to a Windows Instance

The Amazon Elastic Block Store (Amazon EBS) offers persistent storage for Amazon EC2 instances through EBS volumes. Amazon EBS provides the ability to create point-in-time consistent snapshots of the volumes, which are then stored in Amazon S3. These snapshots are also replicated across multiple Availability Zones automatically. Snapshots play an …