AWS CLI allows you to configure multiple profiles or accounts using named profile feature.

Once configured, you can switch to any named profiles when running your aws commands.

Steps to switch accounts on AWS CLI:

  1. Configure multiple accounts or profiles for AWS CLI.
  2. List existing named profiles on your system.
    $ cat .aws/credentials 
    [default]
    aws_access_key_id = AKIAJ3TE4LUDC4I6SQDQ
    aws_secret_access_key = Ibt05WpUQ33Wqkig8HijqDeZd0wyr+hHJoQy/RMz
    [second_user]
    aws_access_key_id = AKIAJF4JT25ZZYGCTTVA
    aws_secret_access_key = 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
  3. Execute aws command with --profile option and the profile name.
    $ aws s3 ls --profile second_user
    
    An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied

    The IAM user configured for the profile does not have S3 access, so the error is expected.

Discuss the article:

Comment anonymously. Login not required.

Share!