# AWS Command Line Interface (CLI)

### AWS Command Line Interface

Today we will be setting up our AWS CLI.

AWS CLI is a tool that lets us manage AWS services from the command line. With AWS CLI, we can control various AWS services and automate tasks through scripts.

To use AWS CLI, we need to configure it with access keys that grant the necessary permissions to perform actions on AWS resources. These access keys are part of AWS Identity and Access Management (IAM).

---

### IAM Access Keys

IAM (Identity and Access Management) access keys are a pair of security credentials that AWS uses to authenticate and authorize API calls. These keys are associated with an IAM user and consist of two parts:

1. **Access Key ID**: A unique identifier for the access key.
    
2. **Secret Access Key**: A secret key used to sign requests.
    

**Purpose**

IAM access keys allow programmatic access to AWS services via the AWS CLI (Command Line Interface), AWS SDKs (Software Development Kits), and other tools that make API requests to AWS services.

When creating access keys, it is essential to use the `IAMAdmin` role or another appropriate IAM role. Creating **access keys for the root account is not recommended** due to security concerns.

Let's create our Access keys.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1718243313322/1128d3b6-4d15-41a6-a938-d3b1df60ae06.png align="left")

Click on your **profile** and select `Security credentials`.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1718243430931/17eb2bbf-121a-42ad-ab2b-a9cb46326601.png align="left")

Scroll a bit and you will find the **Access keys** section.

Click on `Create access key`.

Choose **CLI** for Use case, tick the confirmation box and click on `Next`.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1718245111147/34a27507-274a-4538-87f5-72c808196e4f.png align="left")

Provide a description tag for your Access key.

Click on `Create access key`.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1718245225208/780402ce-caeb-4993-88ad-b05da8004ebf.png align="left")

Our access key has been created.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1718245201826/0c4afb26-8200-42f7-8e4e-0052487ab958.png align="left")

We can see that this is the only time we can view or download our secret key. However, if we lose it, we can create a new one.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1718245352698/2a9a7dda-9c35-4e7b-ac59-6b201f7548a0.png align="left")

Click on `Download .csv file` and store it securely in your local machine.

Click on `Done`.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1718245463321/7625a41d-f519-4477-acff-3a81d5633a22.png align="left")

We have created our access keys. We can create **up to two access keys** in total. Access keys can be **created, deleted, activated,** and **deactivated**.

---

### Downloading AWS CLI

Now that we have created & downloaded our access keys, it's time to download the AWS CLI on our local machine.

[AWS CLI](https://aws.amazon.com/cli/)

Click the link above to download AWS CLI.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1718245790494/3f31953e-cd79-40e3-a781-4140d35c80cb.png align="left")

Choose according to your operating system.

Configure all the setup, and after your setup is successful, type the following command.

```python
aws --version
```

The command displays the installed version of the AWS CLI on your machine.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1718267627061/66bad602-9087-4a73-8955-edc1b8821014.png align="center")

---

### Configuration

Type the following command to configure your AWS CLI.

```python
aws configure
```

The command is used to configure your credentials for the AWS CLI. It will ask for your **access key ID**, **secret access key**, **default region name** (use the closest region code, e.g., us-east-1) & skip the **default output format** field associated with your IAM user.

After you have configured your credentials, input the following command.

```python
aws configure list
```

The command displays information about the profiles you have configured for interacting with AWS services.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1718262334198/856ea8c8-f2eb-4190-bd5c-49ec1d46b122.png align="center")

You must see your configured profile.

---

### Simple Commands

Let's use simple AWS CLI commands.

```python
aws s3 ls #to list the S3 buckets.
```

The command is used to list the S3 buckets.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1718362426500/4faa4a5b-3a80-47c3-be99-b485fb901cbb.png align="left")

As I do not have any buckets created, it is showing empty.

```python
aws iam list-users #to list all IAM users
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1718266032417/b7320345-5d58-45c5-81df-06adafe4e6cf.png align="center")

We used simple AWS CLI commands. Now that our AWS CLI is set up, we can do many AWS operations from the command line but more on that later.

Thank you.
