Bootstrap FreeKB - Amazon Web Services (AWS) - Set Profile Config using the AWS CLI
Amazon Web Services (AWS) - Set Profile Config using the AWS CLI


aws configure set can be used to set certain configurations. By default, this will set configurations in these files.

  • /home/username/.aws/config
  • /home/username/.aws/credentials

This assumes you have created an IAM (Identity and Access Management) User Account and have also created the users Access Key and Secret Key. If not, check out my article Create IAM User using the AWS CLI.

If you want to target config and credentials files in some other location, you can set the AWS_CONFIG_FILE and AWS_SHARED_CREDENTIALS_FILE variables.

export AWS_CONFIG_FILE="/usr/local/aws/config"
export AWS_SHARED_CREDENTIALS_FILE="/usr/local/aws/credentials"

 

Here is how you could set region.

aws configure set default.region us-east-2
aws configure set region us-east-1 --profile development
aws configure set region us-east-2 --profile staging
aws configure set region us-east-2 --profile production

 

And output format.

aws configure set default.output json
aws configure set output json --profile development
aws configure set output json --profile staging
aws configure set output json --profile production

 

This should create a config file with matching key value pairs.

~]$ cat /home/john.doe/.aws/config 
[default]
region = us-east-2
output = json
[profile development]
region = us-east-1
output = json
[profile staging]
region = us-east-2
output = json
[profile production]
region = us-east-2
output = json

 

You can also set your access key. You have one and only one opportunity to get the access key value, when you create the access key. If you misplace the access key value, there is no way to recover the access key value. The aws iam create-access-key command can be used to create a users access key. Make note of the value!

~]$ aws iam create-access-key --user-name john.doe
{
    "AccessKey": {
        "UserName": "john.doe",
        "AccessKeyId": "AKIAABDCL76GBNCJ1235",
        "Status": "Active",
        "SecretAccessKey": "Fd0vB55rDXABCDB3wVUnkE1234vx+dgI1234HQqC",
        "CreateDate": "2023-03-22T01:55:29+00:00"
    }
}

 

Here is how to set the access key value.

aws configure set default.aws_secret_access_key Xw3kZVaxTfvDKBMGf6R79Unf5LG4kdf9piuHfhn13
aws configure set aws_secret_access_key Xw3kZVaxTfvDKBMGf6R79Unf5LG4kdf9piuHfhn13 --profile development
aws configure set aws_secret_access_key fmG74A8cAXa96LWrWw1dkm565bgAtPvMy6yfjm2s --profile staging
aws configure set aws_secret_access_key fj1a5YG2rGYzE99Ccdfhn#RQaU4pZ+H3ehFgm567 --profile production

 

And key ID.

aws configure set default.aws_access_key_id 34VGB4HYOC2ABCO67BKD
aws configure set aws_access_key_id 34VGB4HYOC2ABCO67BKD --profile development
aws configure set aws_access_key_id 34CDSCNDE3E675K67BKD --profile staging
aws configure set aws_access_key_id ZMKF1MMUDGUZR7XFJM90 --profile production

 

This should create a credentails file with matching key value pairs.

~]$ cat /home/john.doe/.aws/credentials 
[default]
aws_secret_access_key = Xw3kZVaxTfvDKBMGf6R79Unf5LG4kdf9piuHfhn13
aws_access_key_id = 34VGB4HYOC2ABCO67BKD
[development]
aws_secret_access_key = Xw3kZVaxTfvDKBMGf6R79Unf5LG4kdf9piuHfhn13
aws_access_key_id = 34VGB4HYOC2ABCO67BKD
[staging]
aws_secret_access_key = fmG74A8cAXa96LWrWw1dkm565bgAtPvMy6yfjm2s 
aws_access_key_id = 34CDSCNDE3E675K67BKD 
[production]
aws_secret_access_key = fj1a5YG2rGYzE99Ccdfhn#RQaU4pZ+H3ehFgm567
aws_access_key_id = ZMKF1MMUDGUZR7XFJM90

 

Or you could export AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as a temporary solution in your current SSH session.

export AWS_ACCESS_KEY_ID=ABCDEFG123456789
export AWS_SECRET_ACCESS_KEY=ABCDEFG123456789ABCDEFG123456789ABCDEFG123456789

 

And now the aws configure list command should have values set.

]$ aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key     ****************7BKD shared-credentials-file    
secret_key     ****************hn13 shared-credentials-file    
    region                us-east-2      config-file    ~/.aws/config

 

The --profile option can be used to show the configuration for a particular profile.

~]$ aws configure list --profile personal
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                 personal           manual    --profile
access_key     ****************MI3W shared-credentials-file    
secret_key     ****************SL9l shared-credentials-file    
    region                <not set>             None    None

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 6a2375 in the box below so that we can be sure you are a human.