Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Amazon EC2 Cookbook

You're reading from   Amazon EC2 Cookbook Over 40 hands-on recipes to develop and deploy real-world applications using Amazon EC2

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher Packt
ISBN-13 9781785280047
Length 194 pages
Edition 1st Edition
Arrow right icon
Toc

Table of Contents (10) Chapters Close

Preface 1. Selecting and Configuring Amazon EC2 Instances FREE CHAPTER 2. Configuring and Securing a Virtual Private Cloud 3. Managing AWS Resources Using AWS CloudFormation 4. Securing Access to Amazon EC2 Instances 5. Monitoring Amazon EC2 Instances 6. Using AWS Data Services 7. Accessing Other AWS Services 8. Deploying AWS Applications Index

Preparing AWS CLI tools

AWS CLI is a set of unified command-line tools to work with multiple AWS services. Using AWS CLI tools you can manage EC2 resources (such as instances, security groups, and volumes) and your VPC resources (such as VPCs, subnets, route tables, and Internet gateways).

How to do it…

In the following two sections, we list the set of instructions required to accomplish this on Linux and Windows/Mac platforms.

Getting access key ID and secret access key

You need AWS access key ID and AWS secret access key to access AWS services. Instead of generating these credentials from the root account, it's always best practice to use IAM users. You should save these credentials in a secure location. If you lose these keys, you must delete the access key and then create a new key.

You can get the AWS credentials from AWS management portal by following these steps:

  1. Log in to the AWS management portal using your AWS username and password.
  2. Select account name from top menu at the right corner in the console.
  3. Select security credentials.
  4. Click on access keys (access key ID and secret access key).
  5. Click on the Create New Access Key button.
  6. Click on Download Key File, which will download the file. If you do not download the key file now, you will not be able to retrieve your secret access key again.
  7. Copy this key file to a secure location.

    Note

    Don't upload your code base with AWS security credentials to public code repositories such as GitHub. Attackers are scraping GitHub for AWS credentials. If anyone gets access to these credentials, they can misuse your AWS account.

Installing AWS CLI using pip in Linux

We can use the pip tool to install the Python packages.

  1. Before installing Python, please check whether Python is already installed on your machine or not using the following command. If Python is already installed on your machine, then skip to the pip installation step.
    $ python --help
    
  2. Start by installing Python. Download the compressed TAR archive file from the Python site, and then install it using the commands listed below. The following steps target the apt-based Linux distributions:
    $ sudo apt-get install gcc
    $ wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
    $ tar -zxvf Python-2.7.8.tgz
    $ cd Python-2.7.8
    $ ./configure
    $ make
    $ sudo make install
    
  3. Next, check the Python installation:
    $ python –help
    
  4. Before installing pip, please check whether pip is already installed on your machine or not by using the following command. If pip is already installed on your machine, then skip to the awscli installation step:
    $ pip –help
    
  5. Move on to installing pip:
    $ sudo apt-get install pip
    
  6. Then install AWS CLI. If you have already installed awscli, you can upgrade the installation using the –upgrade option.
    $ sudo pip install awscli
    
  7. Next, configure AWS CLI.

    On the command prompt, type the following command, which will prompt for the AWSAccessKey ID, AWSSecretKey, default AWS region, and default output format.

    $ sudo aws configure
    
  8. Finally, check the installation by getting regions list:
    $ sudo aws ec2 describe-regions
    

Installing AWS CLI using pip in Windows/Mac

We can use the pip tool to install the Python packages.

  1. Before installing Python, please check whether Python is already installed on your machine or not by using the following command. If Python is already installed on your machine, then skip to the pip installation step.
    $ python –help
    
  2. Start by installing Python. Download the installer from the following URL and install Python by using that installer: https://www.python.org/downloads/.
  3. Check your Python installation:
    $ python –help
    
  4. Before installing pip, check whether pip is already installed on your machine or not by using the following command. If pip is already installed on your machine, skip to the awscli installation step.
    $ pip –help
    
  5. In the next step, we install pip. Download and run the installation script from https://bootstrap.pypa.io/get-pip.py. After that, run the following command:
    $ python get-pip.py
    
  6. Install AWS CLI. If you have already installed awscli, you can upgrade the installation using the –upgrade option.
    $ pip install awscli
    
  7. Next, we configure AWS CLI. Execute the following command from the command prompt.
    $ aws configure
    

    This command will then prompt you for the AWSAccessKey ID, AWSSecretKey, default AWS region, and default output format.

  8. Check the installation by getting the regions list:
    $ aws ec2 describe-regions
    
You have been reading a chapter from
Amazon EC2 Cookbook
Published in: Nov 2015
Publisher: Packt
ISBN-13: 9781785280047
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime