Preparing AWS CLI tools
AWS CLI is a set of unified command-line tools to work with multiple AWS services. Using AWS CLI tools you can manage EC2 resources (such as instances, security groups, and volumes) and your VPC resources (such as VPCs, subnets, route tables, and Internet gateways).
How to do it…
In the following two sections, we list the set of instructions required to accomplish this on Linux and Windows/Mac platforms.
Getting access key ID and secret access key
You need AWS access key ID and AWS secret access key to access AWS services. Instead of generating these credentials from the root account, it's always best practice to use IAM users. You should save these credentials in a secure location. If you lose these keys, you must delete the access key and then create a new key.
You can get the AWS credentials from AWS management portal by following these steps:
- Log in to the AWS management portal using your AWS username and password.
- Select account name from top menu at the right corner in the console.
- Select security credentials.
- Click on access keys (access key ID and secret access key).
- Click on the Create New Access Key button.
- Click on Download Key File, which will download the file. If you do not download the key file now, you will not be able to retrieve your secret access key again.
- Copy this key file to a secure location.
Note
Don't upload your code base with AWS security credentials to public code repositories such as GitHub. Attackers are scraping GitHub for AWS credentials. If anyone gets access to these credentials, they can misuse your AWS account.
Installing AWS CLI using pip in Linux
We can use the pip
tool to install the Python packages.
- Before installing Python, please check whether Python is already installed on your machine or not using the following command. If Python is already installed on your machine, then skip to the
pip
installation step.$ python --help
- Start by installing Python. Download the compressed TAR archive file from the Python site, and then install it using the commands listed below. The following steps target the apt-based Linux distributions:
$ sudo apt-get install gcc $ wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz $ tar -zxvf Python-2.7.8.tgz $ cd Python-2.7.8 $ ./configure $ make $ sudo make install
- Next, check the Python installation:
$ python –help
- Before installing
pip
, please check whetherpip
is already installed on your machine or not by using the following command. Ifpip
is already installed on your machine, then skip to theawscli
installation step:$ pip –help
- Move on to installing
pip
:$ sudo apt-get install pip
- Then install AWS CLI. If you have already installed
awscli
, you can upgrade the installation using the–upgrade
option.$ sudo pip install awscli
- Next, configure AWS CLI.
On the command prompt, type the following command, which will prompt for the
AWSAccessKey
ID,AWSSecretKey
, default AWS region, and default output format.$ sudo aws configure
- Finally, check the installation by getting regions list:
$ sudo aws ec2 describe-regions
Installing AWS CLI using pip in Windows/Mac
We can use the pip
tool to install the Python packages.
- Before installing Python, please check whether Python is already installed on your machine or not by using the following command. If Python is already installed on your machine, then skip to the
pip
installation step.$ python –help
- Start by installing Python. Download the installer from the following URL and install Python by using that installer: https://www.python.org/downloads/.
- Check your Python installation:
$ python –help
- Before installing
pip
, check whetherpip
is already installed on your machine or not by using the following command. Ifpip
is already installed on your machine, skip to theawscli
installation step.$ pip –help
- In the next step, we install
pip
. Download and run the installation script from https://bootstrap.pypa.io/get-pip.py. After that, run the following command:$ python get-pip.py
- Install AWS CLI. If you have already installed
awscli
, you can upgrade the installation using the–upgrade
option.$ pip install awscli
- Next, we configure AWS CLI. Execute the following command from the command prompt.
$ aws configure
This command will then prompt you for the
AWSAccessKey
ID,AWSSecretKey
, default AWS region, and default output format. - Check the installation by getting the regions list:
$ aws ec2 describe-regions