Amazon EC2 (AWS) CLI tools (Command Line Tools) wrap the Amazon EC2 API actions. These tools help us to Manage Amazon EC2 services through command line interface. We can also use them inside scripts for task automation like backups, creating snapshots etc.
The Amazon EC2 command line tools required Java 1.6 or later version. Make sure you have proper java installed on your system. You can install JRE or JDK , both are ok to use.
java -versionjava version " 1.8.0_05" Java(TM) SE Runtime Environment (build 1.8.0_05-b13) Java HotSpot(TM) Client VM (build 25.5-b02, mixed mode)
If you don’t have Java installed your system, Use below links to install Java on your system first
Download and Setup the CLI Tools
Now download the Amazon API CLI tools using following command and extract them at a proper place. For this example, we are using /opt directory.
# mkdir /opt/ec2 # wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip # unzip ec2-api-tools.zip -d /tmp # mv /tmp/ec2-api-tools-* /opt/ec2/tools
Generate AWS AccessKey and SecretKey
Now you are required to generate Access Key and Secret Key in your Amazon account. Get these security keys from aws securityCredentials page. If will prompt to login to your amazon account.
Now edit any startup script like ~/.bashrc file and add the following commends at end of the file. So that all the default values will load on system bootup.
export EC2_BASE=/opt/ec2 export EC2_HOME=$EC2_BASE/tools export AWS_ACCESS_KEY="XXXXXXXXXXXXXXX" export AWS_SECRET_KEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" export EC2_URL=https://ec2.xxxxxxx.amazonaws.com export PATH=$PATH:$EC2_HOME/bin export JAVA_HOME=/opt/jdk1.8.0_05
Set the EC2_URL with your correct url. If you don’t know it, You can get this value from next step. Now execute the following command to set environment variables
$ source ~/.bashrc
Verify EC2 Tools Setup
After completing all configuration, let’s run following command to quickly verify setup.
ec2-describe-regions --access-key=$AWS_ACCESS_KEY --secret-key=$AWS_SECRET_KEYREGION eu-west-1 ec2.eu-west-1.amazonaws.com REGION sa-east-1 ec2.sa-east-1.amazonaws.com REGION us-east-1 ec2.us-east-1.amazonaws.com REGION ap-northeast-1 ec2.ap-northeast-1.amazonaws.com REGION us-west-2 ec2.us-west-2.amazonaws.com REGION us-west-1 ec2.us-west-1.amazonaws.com REGION ap-southeast-1 ec2.ap-southeast-1.amazonaws.com REGION ap-southeast-2 ec2.ap-southeast-2.amazonaws.com