# Day #42: IAM Programmatic access and AWS CLI

## IAM Programmatic access

In order to access your AWS account from a terminal or system, you can use AWS Access keys and AWS Secret Access keys.

## AWS CLI

The AWS Command Line Interface (AWS 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.

The AWS CLI v2 offers several new features including improved installers, new configuration options such as AWS IAM Identity Center (successor to AWS SSO), and various interactive features.

## Task-01

* Create AWS\_ACCESS\_KEY\_ID and AWS\_SECRET\_ACCESS\_KEY from AWS Console.
    

## Task-02

* Setup and install AWS CLI and configure your account credentials
    

### **Create IAM User**

Login to [**AWS Console**](https://aws.amazon.com/) and navigate to the IAM service.

![Screenshot 2021-07-01 at 7.06.06 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1625146716915/sP07vm3Q4.png?auto=compress,format&format=webp align="left")

On the IAM Dashboard, Select the **Users** section and click the `Add User` button.

![Screenshot 2021-07-01 at 7.08.35 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1625147009494/qi8GLCpUl.png?auto=compress,format&format=webp align="left")

Enter an appropriate user name (for this post, I have created a user with the name `demo-user`) and enable **Programmatic Access**. Click the `Next: Permissions` button.

![Screenshot 2021-07-01 at 7.14.05 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1625147186247/bgKZQa1dw.png?auto=compress,format&format=webp align="left")

Now we need to provide a set of relevant permissions to this new user. These permissions will provide the capability to perform certain actions in AWS(e.g. Create EC2 instance, Create IAM Roles / Policies, or even Admin privileges)

For the sake of this demo, we will grant `EC2 Full Access` to our user `demo-user`. Select **Attach existing policies directly** and provide a filter as `EC2`. Select Policy name `AmazonEC2FullAccess` from the list.

![Screenshot 2021-07-01 at 7.25.38 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1625147944486/_MZyUHLFD.png?auto=compress,format&format=webp align="left")

Click `Next: Tags` button. For this demo, we will skip this section. Click the `Next: Review` button.

![Screenshot 2021-07-01 at 7.29.18 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1625148091699/AyJ_odEFy.png?auto=compress,format&format=webp align="left")

Validate the details and then click the `Create user` button.

Copy both Access key ID and Secret access key. As the secret key will visible only once, it is advisable to download the `.csv` file with the credentials.

![Screenshot 2021-07-01 at 7.32.50 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1625148346349/7RGQ5geyu.png?auto=compress,format&format=webp align="left")

### Configure AWS CLI ver 2.0

Based upon the OS, there are different ways to [**install**](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) AWS CLI.

Post-installation, let us fire the following command on the CLI. This will set up an AWS default profile.

**COPY**

```plaintext
aws configure
```

We can also create a specific profile.

**COPY**

```plaintext
aws configure --profile <profie-name>
```

![Screenshot 2021-07-01 at 8.19.42 PM.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1625151496926/XILl8g4_0.png?auto=compress,format&format=webp align="left")

  
Open the Amazon Management Console and log in.

* At the top right corner of the console, click on your username, and then choose "Security Credentials" from the drop-down list.
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQGTZjw2bdTwsA/article-inline_image-shrink_1500_2232/0/1678947335732?e=1692230400&v=beta&t=B_sDZuE6Q28DrO7dHeHCV9F_giw1dQ9ROLvQG81e08g align="left")

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQGk6onELr_kKA/article-inline_image-shrink_1500_2232/0/1678947378283?e=1692230400&v=beta&t=F6oG52ZNVphqcpvjoce3vMNIMvOQP0uP-0m729z-GmE align="left")

* Click on the "Access keys (access key ID and secret access key)" section.
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQElsAtXP4JfZA/article-inline_image-shrink_1500_2232/0/1678947418776?e=1692230400&v=beta&t=q1ff3at-LY5w79WVF6zmJbT5QsudctIWQ1WQrlmy230 align="left")

* Simply select "Create Access Key."
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQHebuYN5FXUQQ/article-inline_image-shrink_1500_2232/0/1678947484611?e=1692230400&v=beta&t=ZqicsNKcAEmiukXyYMhuVMbBVS_VhNI-eZmc0oT76eY align="left")

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQGt90b96K-Fww/article-inline_image-shrink_1500_2232/0/1678947494247?e=1692230400&v=beta&t=ZggplVkpopBofIwq5vughsQ3FrJOnccDKW0GsCabVQ8 align="left")

* You will see both your secret access key and access key ID. Make sure to save the CSV file with your access key information in a safe place after downloading it.
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQEAAv0MoiBMCg/article-inline_image-shrink_1500_2232/0/1678947554880?e=1692230400&v=beta&t=ld7KM6y1xBb_QZ-aluHJXqVAjPyRSiABS5pb4nJgxR8 align="left")

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQG7YoUqBlnwoA/article-inline_image-shrink_1500_2232/0/1678947578715?e=1692230400&v=beta&t=BeP23LTMtNFx_aAV4l6UFdDfRsppFAY0bLYYgtTuXk0 align="left")

### Task-02

Setup and install AWS CLI and configure your account credentials

Install the AWS CLI by following the instructions for your operating system: [https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQFFNr9k0DRQ0A/article-inline_image-shrink_1500_2232/0/1678947615231?e=1692230400&v=beta&t=3MlSFTeS3WFnP3fHcuvQ8QTQs0c9qt_FORgbYmYod2M align="left")

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQFTilbtS7--0g/article-inline_image-shrink_1500_2232/0/1678947634729?e=1692230400&v=beta&t=cTmLh6-mH61r0Wna2YPm8RYpUXrwQ5-wOmeGh7McDFQ align="left")

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQF7o0mRXI1-dQ/article-inline_image-shrink_1500_2232/0/1678947655929?e=1692230400&v=beta&t=CTc9XMLHPThvfG8MJ2AoApv8co_v3bt71CC9u1gdLrQ align="left")

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQFPc-gzGU8_VA/article-inline_image-shrink_1500_2232/0/1678947672332?e=1692230400&v=beta&t=qGGCEjqaeIrRGsSbAytaOBjSFsn1UVBtGoRhZ_owEVw align="left")

* Verify the aws-cli version
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQH4JU4SE38flg/article-inline_image-shrink_1500_2232/0/1678947754174?e=1692230400&v=beta&t=FH8YzDSnftA99uvYvo2GFdo0_aflC-YXCfB-h5OjB1k align="left")

Open a terminal or command prompt after installing the Amazon CLI, then enter the following command to set up your account credentials:

Your AWS Access Key ID and Secret Access Key must be entered when requested. The access key and secret key from the downloaded csv file should be copied and pasted. Input for your default region and output format will also be requested. Select an appropriate output format and the region that is nearest to your location.

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQEl0xwY-Ro7zQ/article-inline_image-shrink_1500_2232/0/1678947823590?e=1692230400&v=beta&t=ZK88PQPuFMmCGsJtatqDcYQK0GgNbrW5CP37Zq-B5O4 align="left")

* After setting up your default settings and entering your credentials, you may execute the following command to see if the CLI is operational:
    

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQFzitspHXk6Mg/article-inline_image-shrink_1500_2232/0/1678947881274?e=1692230400&v=beta&t=bvzY909_eGqXFwc20bwucg2f-Ep2IInayFjfXa3MGDs align="left")

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQE7wlPaBP1mPg/article-inline_image-shrink_1500_2232/0/1678947894558?e=1692230400&v=beta&t=PPgNzPnhIcjlw1CwNy41AiCOUT-XjK1ye6Y93hDQw8c align="left")

Your default S3 bucket's contents should be listed by this command. Now that the Amazon CLI has been installed and set up, you may set up your account credentials.
