Last Updated on 2 weeks by Sachin G
This post explains how to set up AWS EC2 CLI tools on CentOS, RHEL Linux, or Mac OS X. It covers installing the latest version of Java, downloading and extracting EC2 CLI tools, setting environment variables, and verifying the setup by running EC2 commands to list AWS instances and regions.
The Amazon command line interface tool is called as in short EC2 CLI tools that is composed in Java and includes shell scripts for most Linux and Windows-based machines. Before configuring EC2 API CLI tools , we need to install java JRE ( Java Runtime Environment) because tools are wrtten in Java Programming Language and also set Environment of Java .
Here we will follow steps below to setting up the cli on different Linux environments.
(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.
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
I’m Sachin Gupta — a freelance IT support specialist and founder of Tech Transit. I’m certified in Linux, Ansible, OpenShift (Red Hat), cPanel, and ITIL, with over 15 years of hands-on experience. I create beginner-friendly Linux tutorials, help with Ansible automation, and offer IT support on platforms like Upwork, Freelancer, and PeoplePerHour. Follow Tech Transit for practical tips, hosting guides, and real-world Linux expertise!