Last Updated on 8 years by

The Amazon command line interface tool is  called as in short  EC2 CLI tools that is composed in Java and included shell scripts for most of the linux and windows based machines. Before configuring EC2  API CLI tools , we need to install java JRE ( Java Runtime Environment) because tool are wrtten in Java Programming Language and also set Environment of Java .

Here we will follow below steps to setting up the cli on different Linux environment.

(1) Install of Java Latest Version

(2) Download the EC2 CLI tools

(3) Setting up CLI tool location

(4) Cinfigure Identity Location

(5) Verify EC2 Tools Setup

(1) Installation of Java Latest Version

Earlier we have already explain on our post to install , Update and configure Java Environment on linux, You can find below two links for java install and update.Follow below links for java invironment set.

Install and Upgrade Java Version 

Install Java on CentOs , RHEL etc…

Here is my system output :

[root@server jdk1.8.0_60]# java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

(2) Download the EC2 CLI tools 

Here i have a download link from Amazon for EC2 API CLI Tools , You can simply download the tool and extract and configure some variables. Please find below download link for EC2 API tool.

Download  API Tools

Run below command to download and extract  API Tool.

# mkdir /opt/ec-tool

#cd /tmp

# wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip

# unzip ec2-api-tools.zip

# mv /tmp/ec2-api-tools-* /opt/ec-tool/tools

(3) Setting up CLI tool location

For Setting up Environment of EC2 tools We need some security credentials from AWS Console like AccessKey and SecretKey. You can get key from page security Credentials .

If you are using bash shell, you can set variables path in your ~/.bash_profile .Add the below line in ~/.bash_profile file and make changes according to you .

export EC2_BASE=/opt/ec-tool/
export EC2_HOME=$EC2_BASE/tools
export AWS_ACCESS_KEY="XXXXXXXXXXXXXXXXXXXX"
export AWS_SECRET_KEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
export PATH=$PATH:$EC2_HOME/bin
export JAVA_HOME=/opt/jdk1.8.0_60
export EC2_URL=https://us-east-1.ec2.amazonaws.com

Here i have set my default region us-east-1, You will make according to you , update your ACCESS_KEY and SECRET_KEY ID.

To update and set variable in ~/.bash_profile run below command.

# source ~/.bash_profile

(4)Verify  Set Up :

After set environment variable you can test through below command , Here is two basis command for check and verify setup . Run the below command , this will show a list of the aws instances which is currently connected to this account and whole information about instance like Id, DNS, ip etc  in your default region.

# ec2-describe-instances

Now run the below command.You will get all region which is currently associated with this account.

# ec2-describe-regions --aws-access-key=$AWS_ACCESS_KEY --aws-secret-key=$AWS_SECRET_KEY
REGION eu-west-1 ec2.eu-west-1.amazonaws.com
REGION ap-southeast-1 ec2.ap-southeast-1.amazonaws.com
REGION ap-southeast-2 ec2.ap-southeast-2.amazonaws.com
REGION eu-central-1 ec2.eu-central-1.amazonaws.com
REGION ap-northeast-1 ec2.ap-northeast-1.amazonaws.com
REGION us-east-1 ec2.us-east-1.amazonaws.com
REGION sa-east-1 ec2.sa-east-1.amazonaws.com
REGION us-west-1 ec2.us-west-1.amazonaws.com
REGION us-west-2 ec2.us-west-2.amazonaws.com