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:
1 2 3 4 |
[default] aws_access_key_id=AKIAIOSFODNN7EXAMPLE aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY aws_security_token=texample123324 |
This has a default profile , that gets created when you run “ aws configure “
To create this profile enter:
1 2 3 4 5 |
$ aws configure AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default region name [None]: eu-west-1 Default output format [None]: |
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 ) :
1 2 3 4 5 |
$ aws configure --profile user2 AWS Access Key ID [None]: AKIAI44QH8DHBEXAMPLE AWS Secret Access Key [None]: je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY Default region name [None]: us-east-1 Default output format [None]: text |
Now when you want to use this different profile for a simple command you use the profile parameter -profile
1 2 |
aws s3 ls –profile test-user aws s3 ls –profile default |
If you want to switch to use a profile for mutiple commands enter:
Windows
1 |
set AWS_DEFAULT_PROFILE=user2 |
Linux, macOS or Unix
1 |
$ export AWS_DEFAULT_PROFILE=user2 |
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