Install AWS CLI On Centos 7

In this guide , We will see how to install AWS CLI on Centos 7

What Is AWS CLI?

The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.

Versions Of AWSCLI

Version 1.x : The generally available version of AWS CLI, Which can be used in Production environments.

Version 2.x : This is the preview version of AWS CLI which is suitable to be used in Testing Environments.

Example

Here is the command which is used to copy files from local machine to S3 bucket using AWS CLI.

aws s3 cp filename s3://bucketname/

Installing AWS CLI

Method 1: Installing Using Bundled Installer

For offline or automated installations on Linux and MacOS, You can use this Method.

Prerequisites

OS: Linux , MacOS

Python: Python 2 version 2.7+ or Python 3 version 3.4+

You can downloaded the bundler directly using the below link,

https://s3.amazonaws.com/aws-cli/awscli-bundle.zip

We will use curl to download and install using below commands,

curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"

Extract the files from the bundle,

unzip awscli-bundle.zip

Run the script,

sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

Check the installation using the command,

/usr/local/bin/aws --version

Method 2: Installing Using PIP

The pip package manager for Python provides an easy way to install, upgrade, and remove Python packages and their dependencies.

If you already have a pip installed in your machine , with support python version, Install AWS CLI using pip3 If you are using python 3.x+.

If you don’t have python installed in your machine.Install it using command,

yum install python

Then we need to install pip.

Using the below commands , We can install pip on centos 7.

yum install epel-release
yum install python-pip

Then using the pip command we can install aws cli.

pip install awscli

After the aws cli package is installed , We can check the version using the below command.

aws --version

Now, We have installed AWS CLI on Centos 7.

Configure AWS CLI

Now we have to configure awscli , For that we need AWS access_key and secret_key. If you dont have, You can go ahead and create it under an IAM users.

To do so, Login to IAM Console,

In the navigation pane , Choose Users ,

AWS CLI

Go to, Security Credentials, Under Access Keys, click create access key

AWS CLI

You can find access and secret key, You can also download as .csv.

Now run the following command to configure AWS CLI,

aws configure

It will access for ACCESS_KEY , SECRET_KEY and AWS_REGION.

AWS CLI

AWS CLI is configured.

You can find the .aws/credentials file in the users home directory.

How To Use Credentials File For Terraform

You can configure multiple profile with different AWS API keys in credentials file as shown below,

[default]
aws_access_key_id = AKIAY3GUEWGWVTEXAMPLE2
aws_secret_access_key = TqzHNX3Pst1GqZusqUkRfwFFEXAMpLecPb4M9Ry
[profile1]
aws_access_key_id = AKIA6SNSQUGWVTEXAMPLE2
aws_secret_access_key = TqzHNX3Pst1GqZusqUkRfwFFEXAMpLecPb4M9Ry

If you want other tools such as TERRAFORM to use these Profile, We need to configure environment variable.

export AWS_PROFILE=profile1

We need to modify terraform main.tf script as shown below,

provider "aws" {
access_key = "${var.profile}"
secret_key = "${var.profile}"
region = "${var.region}"
}

Then we need to define variable in creds.tf,

variable "profile" {
description = "aws credentials for terraform"
}
variable "region" {
default = "ap-southeast-1"
}

if I run terraform commands, It will ask to enter the profile you want to use.

We have worked on how to install AWS CLI, Configure multiple Profile, and how to Use profiles for Terraform.

Hope you find it helpful.

Please do check out my other articles.