How to setup the AWS CLI for multiple profiles

0 min read 199 words

The AWS CLI provides the ability to use the wide range of Amazon Web Services tools and services straight from the command-line. If you’re working with AWS, you might also be interested in how to push Docker images to AWS ECR or how to get the size of an AWS S3 bucket .

However, sometimes it’s useful to be able to login to multiple AWS accounts. Luckily, this is possible by adding an additional profile to your local configuration and then specifying it when making calls to respective services. This is especially useful when making HTTP requests in AWS Lambda using Python .

Update your local credentials

Step 1. ~/.aws/credentials

[default]
aws_access_key_id = "<MY_FIRST_AWS_KEY_ID>
aws_secret_access_key = "<MY_FIRST_AWS_SCRET_ACCESS_KEY>"

[andrew]
aws_access_key_id = "<MY_SECOND_AWS_KEY_ID>
aws_secret_access_key = "<MY_SECOND_AWS_SCRET_ACCESS_KEY>"

Fill in your own details for the second grouping, mine is called andrew.

Update your local config

Step 2.~/.aws/config

[default]
region = "<region>"
output = "<json/text>"

[profile andrew]
region = "<region>"
output = "<json/text>"

Fill in your own details for the second grouping, mine is called andrew.

Run a test command

Step 3. Run a command

aws sts get-caller-identity --profile andrew

You can find more information about this on the AWS documentation over here: http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-multiple-profiles

Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags