how.wtf

Use multiple AWS accounts using AWS CLI

· Thomas Taylor

Using multiple AWS accounts from the command line is natively handled with profiles in the AWS CLI.

Using aws configure

Using the aws configure command, multiple profiles can be configured.

1aws configure --profile account1
2AWS Access Key ID [None]: ...
3AWS Secret Access Key [None]: ...
4Default region name [None]: ...
5Default output format [None]: ...

Then, the --profile account1 option may be used with future commands.

1aws s3 ls --profile account1

Or an environment variable may be set.

1export AWS_PROFILE=account1
2aws s3 ls # uses account1 credentials

Note: If the profile is named --profile default, it will represent the default profile when no --profile argument is provided.

Manually setting credentials

The ~/.aws/credentials and ~/.aws/config files can be modified directly.

  1. Add the credentials to the ~/.aws/credentials file
1[default]
2aws_access_key_id=accesskey
3aws_secret_access_key=secretaccesskey
4
5[account1]
6aws_access_key_id=accesskey
7aws_secret_access_key=secretaccesskey
  1. Add the profile to the ~/.aws/config file
1[default]
2region=us-east-1
3output=json
4
5[profile account1]
6region=us-east-1
7output=json
  1. Use the --profile argument or set the AWS_PROFILE environment variable.
1aws s3 ls --profile account1

OR

1export AWS_PROFILE=account1
2aws s3 ls # uses account1 credentials

#aws   #aws-cli  

Reply to this post by email ↪