How to use multiple AWS accounts from the command line?

You can configure multiple profiles in the AWS CLI configuration file to use multiple AWS accounts from the command line. Here is a short example for you –

Open a command line and execute aws configure command with –profile parameter for your first AWS account. Provide your first AWS account IAM user’s access key and secret key when prompted.

Perform the same operation for your second AWS account using a different profile name.

Once done, your AWS config and the credential file should content below

Now test your credentials for both accounts to see if they are working

This should return your account ID and username for each AWS account. If you haven’t install AWS CLI yet, follow the below link to install AWS CLI first.

Leave a Reply