Bootstrap FreeKB - Amazon Web Services (AWS) - Getting Started with the AWS CLI
Amazon Web Services (AWS) - Getting Started with the AWS CLI


Many Linux distributions include the Amazon Web Services (AWS) Command Line Interface (CLI), especially AWS EC2 Instances. The which command can be used to determine if the AWS CLI exists in $PATH. In this example, the AWS CLI does exist in $PATH.

~]$ which aws
/usr/local/bin/aws

 

On the other hand, if the which command returns something like this, this means that the AWS CLI is either not installed on your Linux system or is not in $PATH.

~]$ which aws
/usr/bin/aws: no aws in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/john.doe/bin)

 

You can echo $PATH to return the directories being seached for the AWS CLI. This should be the same directories returned by the which command.

~]# echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/john.doe/bin

 

If the AWS CLI is installed in a directory not in $PATH, a temporary solution is to use the export command to add the directory that the AWS CLI is installed in to $PATH.

export PATH=$PATH:/tmp/aws/bin

 

If the AWS CLI is not installed on your Linux system, curl can be used to download the AWS CLI.

curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip --output /tmp/awscliv2.zip

 

unzip can be used to unzip the .zip file.

unzip /tmp/awscliv2.zip -d /tmp

 

The install command can then be used to install the AWS CLI. By default, the AWS CLI will be installed at /usr/local/bin/aws.

sudo /tmp/aws/install

 

The aws configure list command can be used to display the basic configuration you have set for the aws command line tool.

In this example, no configurations have been set.

~]$ aws configure list
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key                <not set>             None    None
secret_key                <not set>             None    None
    region                <not set>             None    None

 

aws configure set can be used to set certain configurations, such as 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 can get your access key in the AWS console at IAM (Identity and Access Management) > Manage access keys.

To create your access key, sign into the AWS console with your ID, at the top right select your name > Security credentials > Create access key.

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

 

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 8ef37b in the box below so that we can be sure you are a human.