Activity overview

The AWS Command Line Interface (AWS CLI) is a command line tool that provides an interface for interacting with products and services from Amazon Web Services (AWS).

Often, people install the AWS CLI directly on their laptop machines. However, in this course—to ensure that all students have the same setup—you will practice using the AWS CLI from an Amazon Elastic Compute Cloud (Amazon EC2) instance.

While some instance types have the AWS CLI pre-installed on them (such as Amazon Linux instances), it is important to know how to install and configure this tool. Therefore, in this activity, you will practice installing the AWS CLI. A Red Hat Linux instance—that does not have the AWS CLI installed on it—is provided for you on Amazon EC2.

You will establish a Secure Shell (SSH) connection to the instance. Then, you will configure the installation with an access key that can connect to an AWS account. Finally, you will practice using the AWS CLI to interact with AWS Identity Access and Management (IAM).

This diagram summarizes the activities you will complete in this activity.

 

Install the AWS CLI on Red Hat Linux

Now that you are connected to the instance, the next step is to install the AWS CLI.

For all steps that are in this section: Complete these steps in the terminal window where you have an active SSH connection to the Red Hat Linux instance running on Amazon EC2.

Verify that Python is installed by running the following command:

 

The command output shows that Python version 2.7.5 is installed.

Tip: To install the AWS CLI, you must have Python 2 version, 2.6.5 or later, or Python 3 version 3.3. If one of these versions was not already installed, you must follow the steps to install Python as documented here.

Run the following command to see if the pip package manager is already installed.

 

This Red Hat instance does not have pip installed.

NOTE: The primary distribution method for the AWS CLI on Linux, Windows, and macOS is pip. Pip is a package manager for Python that provides an easy way to install, upgrade, and remove Python packages and their dependencies.

Download and install the Extra Packages for Enterprise Linux (EPEL) repository, and then install pip by using the following commands:

 

Verify that pip is now installed.

This time, the command output should return a line that indicates the version that was installed (e.g., 8.1.2).

Install the AWS CLI by using pip.

 

NOTE: The --upgrade option tells pip to upgrade any requirements that are already installed. The --user option tells pip to install the program to a subdirectory of your user directory, which helps you avoid modifying the libraries that are used by your operating system.

The installation should succeed.

NOTE: For the purposes of this activity, do not upgrade pip, even if the command output suggests that you do so.

Verify that AWS CLI is now working by running the following command:

 

The help command should display the help information for AWS CLI.

At the : prompt, type q to exit.

 

More help:

Examples

To retrieve information about the specified managed policy

This example returns details about the managed policy whose ARN is arn:aws:iam::123456789012:policy/MySamplePolicy:

aws iam get-policy --policy-arn arn:aws:iam::123456789012:policy/MySamplePolicy

Output:

{
    "Policy": {
        "PolicyName": "MySamplePolicy",
        "CreateDate": "2015-06-17T19:23;32Z",
        "AttachmentCount": 0,
        "IsAttachable": true,
                "PolicyId": "Z27SI6FQMGNQ2EXAMPLE1",
        "DefaultVersionId": "v1",
                "Path": "/",
                "Arn": "arn:aws:iam::123456789012:policy/MySamplePolicy",
                "UpdateDate": "2015-06-17T19:23:32Z"
    }
}

Tip: If you want to use an AWS CLI installation to connect to a different AWS account, run the aws configure command again, and provide the new credentials.