The AWS has launched AWS Command Line Interface (CLI) unified tool to manage your whole AWS services from the command line and automate them through scripts.
You can install AWS CLI on your Linux or Windows machine for managing AWS services from command line.
In this post I have demonstrated how to install and configure the AWS CLI tool and its prerequisite in CentOS Linux. For using AWS CLI on my base Ubuntu 16.04 machine I have made a one CentOS 7 Virtual Machine by using KVM Virtualisation.
On below Python versions AWS CLI can work:
- 2.6.5 and greater
- 2.7.x and greater
- 3.3.x and greater
- 3.4.x and greater
- 3.5.x and greater
- 3.6.x and greater
PIP Package checking and installation before installing AWS CLI:
For installing AWS CLI PIP Package should be installed in your Linux machine. PIP is a special program used to install Python packages to your system. Pip is sometimes included automatically when Python is installed to your system, and sometimes you have to install it yourself. As AWS CLI package is Python based hence PIP package is a mandatory prerequisite package which should be available in your Linux machine
- To check if Python PIP is installed in CentOS 7 VM type command pip –version:
[charanjit@centos7srv1 ~]$ pip --version
pip 7.0.3 from /usr/local/lib/python3.5/dist-packages (python 3.5)
[charanjit@centos7srv1 ~]$
- If PIP package is not installed in Linux machine then PIP Package need to download from Link: https://bootstrap.pypa.io/get-pip.py and install:
[charanjit@centos7srv1 ~]$ wget https://bootstrap.pypa.io/get-pip.py
--2018-04-27 06:10:43-- https://bootstrap.pypa.io/get-pip.py
Resolving bootstrap.pypa.io (bootstrap.pypa.io)... 151.101.8.175, 2a04:4e42:2::175
Connecting to bootstrap.pypa.io (bootstrap.pypa.io)|151.101.8.175|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1642329 (1.6M) [text/x-python]
Saving to: ‘get-pip.py.1’
100%[======================================>] 16,42,329 2.59MB/s in 0.6s
2018-04-27 06:10:44 (2.59 MB/s) - ‘get-pip.py.1’ saved [1642329/1642329]
[charanjit@centos7srv1 ~]$
[charanjit@centos7srv1 ~]$ sudo python get-pip.py
Collecting pip
Downloading pip-7.1.2-py2.py3-none-any.whl (1.1MB)
100% |████████████████████████████████| 1.1MB 448kB/s
Collecting setuptools
Downloading setuptools-18.4-py2.py3-none-any.whl (462kB)
100% |████████████████████████████████| 462kB 676kB/s
Collecting wheel
Downloading wheel-0.26.0-py2.py3-none-any.whl (63kB)
100% |████████████████████████████████| 65kB 912kB/s
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-7.1.2 setuptools-18.4 wheel-0.26.0
[charanjit@centos7srv1 ~]$
Installation of AWS CLI:
- Install the AWS CLI package from PIP.
sudo pip install awscli
- Post installation check the AWS CLI version:
[charanjit@centos7srv1 ~]$ aws --version
aws-cli/1.14.68 Python/3.5 Linux/3.10.0-693.el7.x86_64 botocore/1.9.21
[charanjit@centos7srv1 ~]$
Configuration of AWS CLI:
- Open the IAM console.
- In the navigation pane of the console, choose Users.
- Choose your IAM user name (not the check box).
- Choose the Security credentials tab and then choose Create access key.
- To see the new access key, choose Show. Your credentials will look something like this:
- Access key ID: AKIAIOSFODNN7EXAMPLE
- Secret access key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
- To download the key pair, choose Download .csv file. Store the keys in a secure location.
- Configure the AWS connection with same Access Key ID and Secret Access Key.
[charanjit@centos7srv1 ~]$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json
[charanjit@centos7srv1 ~]
- Now do post configuration check with command: aws ec2 describe-instances –output table
[charanjit@centos7srv1 ~]$ aws ec2 describe-instances --output table
------------------------------------------------------------------------------------
| DescribeInstances |
+----------------------------------------------------------------------------------+
|| Reservations ||
|+---------------------------------+----------------------------------------------+|
|| OwnerId | 882323792697 ||
|| ReservationId | r-037769699a0f3c458 ||
|+---------------------------------+----------------------------------------------+|
||| Instances |||
||+--------------------------+---------------------------------------------------+||
||| AmiLaunchIndex | 0 |||
||| Architecture | x86_64 |||
||| ClientToken | |||
||| EbsOptimized | False |||
||| EnaSupport | True |||
||| Hypervisor | xen |||
||| ImageId | ami-03291866 |||
||| InstanceId | i-0687b720a702dd60e |||
||| InstanceType | t2.micro |||
||| KeyName | EFS_test |||
||| LaunchTime | 2018-04-21T07:14:17.000Z |||
||| PrivateDnsName | ip-172-31-45-97.us-east-2.compute.internal |||
||| PrivateIpAddress | 172.31.45.97 |||
||| PublicDnsName | |||
||| RootDeviceName | /dev/sda1 |||
||| RootDeviceType | ebs |||
||| SourceDestCheck | True |||
||| StateTransitionReason | |||
||| SubnetId | subnet-f65454bb |||
||| VirtualizationType | hvm |||
||| VpcId | vpc-87c9a8ef |||
||+--------------------------+---------------------------------------------------+||
|||| BlockDeviceMappings ||||
|||+--------------------------------------+-------------------------------------+|||
|||| DeviceName | /dev/sda1 ||||
|||+--------------------------------------+-------------------------------------+|||
||||| Ebs |||||
||||+--------------------------------+-----------------------------------------+||||
||||| AttachTime | 2018-04-21T07:14:18.000Z |||||
||||| DeleteOnTermination | True |||||
||||| Status | attached |||||
||||| VolumeId | vol-095714007eee0a2b7 |||||
||||+--------------------------------+-----------------------------------------+||||
|||| Monitoring ||||
|||+-------------------------------+--------------------------------------------+|||
|||| State | disabled ||||
|||+-------------------------------+--------------------------------------------+|||
|||| NetworkInterfaces ||||
|||+-----------------------+----------------------------------------------------+|||
|||| Description | ||||
|||| MacAddress | 0a:62:09:63:93:8e ||||
|||| NetworkInterfaceId | eni-0d372b2a360608244 ||||
|||| OwnerId | 882323792697 ||||
|||| PrivateDnsName | ip-172-31-45-97.us-east-2.compute.internal ||||
|||| PrivateIpAddress | 172.31.45.97 ||||
|||| SourceDestCheck | True ||||
|||| Status | in-use ||||
|||| SubnetId | subnet-f65454bb ||||
|||| VpcId | vpc-87c9a8ef ||||
|||+-----------------------+----------------------------------------------------+|||
||||| Attachment |||||
||||+------------------------------+-------------------------------------------+||||
||||| AttachTime | 2018-04-21T07:14:17.000Z |||||
||||| AttachmentId | eni-attach-062760aa0aed97ec4 |||||
||||| DeleteOnTermination | True |||||
||||| DeviceIndex | 0 |||||
||||| Status | attached |||||
||||+------------------------------+-------------------------------------------+||||
||||| Groups |||||
||||+-------------------------+------------------------------------------------+||||
||||| GroupId | sg-051aad8c2fc42a16f |||||
||||| GroupName | EFS_test |||||
||||+-------------------------+------------------------------------------------+||||
||||| PrivateIpAddresses |||||
||||+---------------------+----------------------------------------------------+||||
||||| Primary | True |||||
||||| PrivateDnsName | ip-172-31-45-97.us-east-2.compute.internal |||||
||||| PrivateIpAddress | 172.31.45.97 |||||
||||+---------------------+----------------------------------------------------+||||
|||| Placement ||||
|||+--------------------------------------------+-------------------------------+|||
|||| AvailabilityZone | us-east-2c ||||
|||| GroupName | ||||
|||| Tenancy | default ||||
|||+--------------------------------------------+-------------------------------+|||
|||| SecurityGroups ||||
|||+-------------------------+--------------------------------------------------+|||
|||| GroupId | sg-051aad8c2fc42a16f ||||
|||| GroupName | EFS_test ||||
|||+-------------------------+--------------------------------------------------+|||
|||| State ||||
|||+-------------------------------+--------------------------------------------+|||
|||| Code | 80 ||||
|||| Name | stopped ||||
|||+-------------------------------+--------------------------------------------+|||
|||| StateReason ||||
|||+---------+------------------------------------------------------------------+|||
|||| Code | Client.InstanceInitiatedShutdown ||||
|||| Message| Client.InstanceInitiatedShutdown: Instance initiated shutdown ||||
|||+---------+------------------------------------------------------------------+|||
|||| Tags ||||
|||+-----------------------+----------------------------------------------------+|||
|||| Key | Name ||||
|||| Value | Redhat-EFS-Test ||||
|||+-----------------------+----------------------------------------------------+|||
|| Reservations ||
|+---------------------------------+----------------------------------------------+|
|| OwnerId | 882323792697 ||
|| ReservationId | r-06a0c03db6cfce40e ||
|+---------------------------------+----------------------------------------------+|
||| Instances |||
||+--------------------------+---------------------------------------------------+||
||| AmiLaunchIndex | 0 |||
||| Architecture | x86_64 |||
||| ClientToken | |||
||| EbsOptimized | False |||
||| EnaSupport | True |||
||| Hypervisor | xen |||
||| ImageId | ami-57d3e732 |||
||| InstanceId | i-0b0536f64d83bed49 |||
||| InstanceType | t2.micro |||
||| KeyName | EFS_test |||
||| LaunchTime | 2018-04-21T06:48:21.000Z |||
||| PrivateDnsName | ip-172-31-40-45.us-east-2.compute.internal |||
||| PrivateIpAddress | 172.31.40.45 |||
||| PublicDnsName | |||
||| RootDeviceName | /dev/sda1 |||
||| RootDeviceType | ebs |||
||| SourceDestCheck | True |||
||| StateTransitionReason | |||
||| SubnetId | subnet-f65454bb |||
||| VirtualizationType | hvm |||
||| VpcId | vpc-87c9a8ef |||
||+--------------------------+---------------------------------------------------+||
|||| BlockDeviceMappings ||||
|||+--------------------------------------+-------------------------------------+|||
|||| DeviceName | /dev/sda1 ||||
|||+--------------------------------------+-------------------------------------+|||
||||| Ebs |||||
||||+--------------------------------+-----------------------------------------+||||
||||| AttachTime | 2018-04-21T05:42:35.000Z |||||
||||| DeleteOnTermination | True |||||
||||| Status | attached |||||
||||| VolumeId | vol-0822eb1d30ac8e030 |||||
||||+--------------------------------+-----------------------------------------+||||
|||| Monitoring ||||
|||+-------------------------------+--------------------------------------------+|||
|||| State | disabled ||||
|||+-------------------------------+--------------------------------------------+|||
|||| NetworkInterfaces ||||
|||+-----------------------+----------------------------------------------------+|||
|||| Description | ||||
|||| MacAddress | 0a:e5:3a:9f:5e:d6 ||||
|||| NetworkInterfaceId | eni-0923d9615adb1b3b7 ||||
|||| OwnerId | 882323792697 ||||
|||| PrivateDnsName | ip-172-31-40-45.us-east-2.compute.internal ||||
|||| PrivateIpAddress | 172.31.40.45 ||||
|||| SourceDestCheck | True ||||
|||| Status | in-use ||||
|||| SubnetId | subnet-f65454bb ||||
|||| VpcId | vpc-87c9a8ef ||||
|||+-----------------------+----------------------------------------------------+|||
||||| Attachment |||||
||||+------------------------------+-------------------------------------------+||||
||||| AttachTime | 2018-04-21T05:42:35.000Z |||||
||||| AttachmentId | eni-attach-0dac92554553dff3b |||||
||||| DeleteOnTermination | True |||||
||||| DeviceIndex | 0 |||||
||||| Status | attached |||||
||||+------------------------------+-------------------------------------------+||||
||||| Groups |||||
||||+-------------------------+------------------------------------------------+||||
||||| GroupId | sg-051aad8c2fc42a16f |||||
||||| GroupName | EFS_test |||||
||||+-------------------------+------------------------------------------------+||||
||||| PrivateIpAddresses |||||
||||+---------------------+----------------------------------------------------+||||
||||| Primary | True |||||
||||| PrivateDnsName | ip-172-31-40-45.us-east-2.compute.internal |||||
||||| PrivateIpAddress | 172.31.40.45 |||||
||||+---------------------+----------------------------------------------------+||||
|||| Placement ||||
|||+--------------------------------------------+-------------------------------+|||
|||| AvailabilityZone | us-east-2c ||||
|||| GroupName | ||||
|||| Tenancy | default ||||
|||+--------------------------------------------+-------------------------------+|||
|||| SecurityGroups ||||
|||+-------------------------+--------------------------------------------------+|||
|||| GroupId | sg-051aad8c2fc42a16f ||||
|||| GroupName | EFS_test ||||
|||+-------------------------+--------------------------------------------------+|||
|||| State ||||
|||+-------------------------------+--------------------------------------------+|||
|||| Code | 80 ||||
|||| Name | stopped ||||
|||+-------------------------------+--------------------------------------------+|||
|||| StateReason ||||
|||+---------+------------------------------------------------------------------+|||
|||| Code | Client.InstanceInitiatedShutdown ||||
|||| Message| Client.InstanceInitiatedShutdown: Instance initiated shutdown ||||
|||+---------+------------------------------------------------------------------+|||
|||| Tags ||||
|||+-------------------------+--------------------------------------------------+|||
|||| Key | Value ||||
|||+-------------------------+--------------------------------------------------+|||
|||| Name | Suse-EFS-test ||||
|||| Name | EFS test ||||
|||+-------------------------+--------------------------------------------------+|||
[charanjit@centos7srv1 ~]$
Good Charan. Keep it up.
Thanks Azad your valuable comments are really motivating me!!
Very informative topic. Thanks for sharing it.
Thank you!
Grt discription , it’s help me a lot …highly thnx for dis