How to Configure AWS CLI?

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):

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

C:\> msiexec.exe /i

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 "" -o ""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:

Leave A Comment

Your email address will not be published. Required fields are marked *