Tech Blog

Cloud Computing

How to Configure AWS CLI?

By Keerthik Shenoy4 min read
← Back to blog

In Cloud platforms such as AWS, GCP, and Azure we have multiple ways to access cloud services and our resources like GUI (Console), CDK, and CLI. In today’s blog, we are going to look at CLI access in AWS.

Like all other cloud providers, AWS also provides CLI access to their services for that first we have to configure AWS CLI on our Laptop. First, let’s see how to do that.

For Windows:

1. Download and run the AWS CLI MSI installer for Windows (64-bit):
https://awscli.amazonaws.com/AWSCLIV2.msi

Alternatively, you can run the msiexec command to run the MSI installer.

C:\> msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi

For various parameters that can be used with msiexec, see msiexec on the Microsoft Docs website.

2. To confirm the installation, open the Start menu, search for cmd to open a command prompt window, and at the command prompt use the aws –version command.

C:\>aws --version
aws-cli/2.7.24 Python/3.8.8 Windows/10 exe/AMD64 prompt/off

For Linux:

For Linux OS like ubuntu, Amazon Linux, or other 64-bit Linux distributions we install AWS CLI using a Linux terminal with a few basic commands

$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"unzip awscliv2.zipsudo ./aws/install

Confirm the installation with the following command.

$ aws --versionaws-cli/2.7.24 Python/3.8.8 Linux/4.14.133-113.105.amzn2.x86_64 botocore/2.4.5

After Successful installation of AWS CLI now it is time to configure the cli with credentials. This configuration part is the same for all Operating systems.

You have to configure the cli credentials for your user in the AWS IAM console.

  • While creating a new user key will get generated automatically if you gave programmatic access to that user.
  • For already created users you can generate new credentials by following the below steps.
  1. In IAM console go to the user section and open the user by double clicking on the user name.
  2. Go to the Security credentials tab in the user summary.
  3. Create new credentials by clicking on Create access key.
  4. Please download the .csv file and keep it somewhere safe. Do not share it with anyone since it is confidential.
  5. After closing this window you can’t see your secret key on your console, you have to check it on the csv file only.

PS: If you lost the key file there is no way to download or view it again from the console you have to generate a new key.

Once user credentials are generated then you can configure AWS CLI on your Laptop, Open CMD or Terminal (Linux) on your laptop and run the below command

$ aws configure

And it will ask for the below details to provide access and secret keys for the downloaded .csv file and configure the region and format as well.

AWS Access Key ID [None]: <your_access_key>AWS Secret Access Key [None]: <your_secret_key>Default region name [None]: ap-south-1Default output format [None]: json

That’s all your AWS CLI configured now you can access AWS using your command line, based on your user permissions.

Some more advanced ways to configure AWS CLI

Importing files:

Alternatively, you can import the .csv file you downloaded after you created your key pair instead of using aws configure.

$ aws configure  import  --csv  file://credentials.csv

Profiles :

A profile is a collection of settings. The default profile is used by the AWS CLI by default. By specifying the –profile option and assigning a name, you can create and use additional named profiles with varying credentials and settings.

The following example creates a profile named produser

$ aws configure  --profile produser

It will create a new prod user profile in  C:\Users\USERNAME\.aws\credentials  in windows and for Linux ~/.aws/credentials

While accessing AWS resources you can mention specific profiles and it user credentials from that profile

$ aws s3 ls -profile produser

AWS CLI Commands:
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/index.html

Keep reading

You may be interested in

Browse all articles →
AWS Automation with Python Boto3
December 30, 20223 min read

AWS Automation with Python Boto3

Automation plays a major role in In Cloud and DevOps, we have many tools to automate manual processes like Infrastructure automation with Terraform, for CICD Jenkins, GitLab, AWS, code pipeline, etc. In the same way, we can automate some of the AWS tasks with a simple python script using the oto3 library. Let’s see some […]

By Keerthik ShenoyRead More →
AWS Cost Optimization Techniques
December 15, 20224 min read

AWS Cost Optimization Techniques

AWS is the world’s leading cloud computing platform, providing a wide range of services including computer computing, storage, networking, and platform as a service (PaaS). AWS cost optimization requires identifying areas for cost-saving measures, tracking your usage, and putting advice into practice. Your Amazon costs are largely influenced by the cost of EC2 instances provided […]

By Keerthik ShenoyRead More →
Terraform As a DevOps Tool (IaC) And Benefits (Part 2)
September 21, 20222 min read

Terraform As a DevOps Tool (IaC) And Benefits (Part 2)

In this article, we will explore terminologies and basic commands that can be used to interact with Terraform. Using Terraform init, an existing or new Terraform configuration can be initialized. As a beginner, you may get syntax errors or indentation errors. To validate theYAML data, use the Terraform “validate” command. The “Terraform apply“ command changes […]

By Utsav SolankiRead More →