
Table of Content
Introduction
Amazon comes with Command Line Interface (CLI) and AMI Tools to manage the instances. CLI tools can be used to create and manage resources for EC2, EBS, and VPC. Whereas, AMI tools can be used to create and manage instance-store backed Linux AMIs. The AWS CLI is a unified tool to manage AWS services. Amazon documentation has very detailed instructions on how to set up these but the main aim of this post is to quickly set up with CLI tools and start using them. This post shows how to install, configure, and verify Amazon CLI tools as this is the basic set up which will be a pre-requisite for many upcoming blog posts.
Use Case
This use case shows how to install and configure Java, and AWS CLI tools on Ubuntu, and perform some verification on the set up to ensure the proper working of the CLI tools.
What we need to do:
- Download & Install Java 1.7
- Download & Install AWS CLI Tools
- Set up Environment Variables
- Verify Setup
Solution
Install Java 1.7:
- Download Java 1.7:
12$ cd /opt$ sudo wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u55-b13/jdk-7u55-linux-x64.tar.gz - Configure Java 1.7:
12345$ sudo tar xf jdk-7u55-linux-x64.tar.gz$ sudo rm jdk-7u55-linux-x64.tar.gz#Create a soft link Java to the extracted directory$ sudo ln -s jdk1.7.0_55 java - Verify:
12345$ /opt/java/bin/java -versionjava version "1.7.0_55"Java(TM) SE Runtime Environment (build 1.7.0_55-b13)Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)
Download & Install AWS CLI Tools:
- Download AWS CLI Tools:
1$ sudo wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip - Configure AWS CLI Tools:
123456$ sudo unzip ec2-api-tools.zip$ sudo rm ec2-api-tools.zip# create a soft link to extracted ec2 tools directory$ sudo ln -s ec2-api-tools-1.7.0.2 ec2-tools
Set up Environment Variables:
- JAVA_HOME Environment Variable:
123456$ cd /home/ubuntu$ vi .bashrc#Add the below export line at the bottom of .bashrc file and save itexport JAVA_HOME="/opt/java" - CLI Tools Environment Variable:
123456789$ vi .bashrc#Add the below export lines at the bottom of .bashrc file and save it. Please use appropriate AWS access and secret keysexport EC2_HOME="/opt/ec2-tools"export AWS_ACCESS_KEY=your-aws-access-keyexport AWS_SECRET_KEY=your-aws-secret-keyexport PATH=$JAVA_HOME/bin:$EC2_HOME/bin:$PATH - Refresh Profile File:
The screenshot given below shows how it looks like:
1 2 3 |
# source the file so that the new environment variables are available for this session $ source .bashrc |
Verify Setup:
- Describe Regions:
$ ec2-describe-regions
- Describe Instances in a Region:
$ ec2-describe-instances –region us-west-2
- Describe Instance Status:
$ ec2-describe-instance-status –region us-west-2 i-16845d1d
Conclusion
- Amazon web-based Console has lot of functionalities with respect to launching instances, assigning security groups, creating EBS volumes, and others. However, Amazon CLI tools can be scripted for easy management and certain functionalities like Auto-Scaling and others are only possible with CLI tools.
- With just one CLI tool, it’s possible to control multiple AWS services from the command line and automate them through scripts.
References
- CLI Commands:
http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/command-reference.html
- Amazon CLI: http://aws.amazon.com/cli/
Pingback: Setup LAMP Server in EC2 Instance with Puppet | Treselle Systems