Installing and Configuring the AWS CLI on Windows

Introduction:

The AWS Command Line Interface (CLI) is a powerful tool that allows you to interact with Amazon Web Services (AWS) from your command line. In this tutorial, you’ll learn how to install and configure the AWS CLI on a Windows machine with Windows Subsystem for Linux 2 (WSL2). This setup provides you with the ability to manage AWS resources directly from your WSL2 terminal.

Prerequisites:

  1. AWS CLI installed on your Windows machine. You can download and install it from here.

  2. An AWS account with appropriate permissions.

Step 1: Open a Windows Command Prompt

  1. Press Win + R to open the Run dialog box.

  2. Type cmd and press Enter to open a Windows Command Prompt.

Step 2: Configure AWS CLI

In the Command Prompt, run the following command to configure the AWS CLI:

aws configure

You will be prompted to enter the following information:

  • AWS Access Key ID: Enter your AWS Access Key ID.

  • AWS Secret Access Key: Enter your AWS Secret Access Key.

  • Default region name: Enter the AWS region you want to use (e.g., us-east-1).

  • Default output format: You can leave this as None or enter a preferred output format (e.g., json).

After entering these details, AWS CLI will confirm that the configuration was successful.

Step 3: Create AWS CLI Credentials File (Optional)

You can choose to create an AWS CLI credentials file to store your credentials securely. Run the following commands in your WSL2 terminal:

Create the .aws directory in your user's home directory:

mkdir ~/.aws

Create the credentials file within the .aws directory:

touch ~/.aws/credentials

Navigate to the credentials file:

cd ~/.aws

Edit the credentials file using a text editor like Nano:

nano credentials

In the credentials file, you can manually add your AWS Access Key ID and Secret Access Key:

[default] aws_access_key_id = YOUR_ACCESS_KEY_ID aws_secret_access_key = YOUR_SECRET_ACCESS_KEY

You can add multiple profiles if you have multiple AWS accounts or IAM users.

Step 4: Confirm AWS CLI Configuration

To confirm that you’ve configured AWS CLI correctly, run the following command in your WSL2 terminal:

aws sts get-caller-identity

You should see information about your AWS account, including your Account ID, User ID, and ARN.

Step 5: Start Using AWS CLI

You can now use the AWS CLI from your Windows Command Prompt or WSL2 terminal to interact with your AWS resources. For example:

aws s3 ls
  • List EC2 instances:
aws ec2 describe-instances

Manage AWS resources as needed using AWS CLI commands.

Conclusion:

Congratulations! You’ve successfully installed and configured the AWS CLI on Windows using WSL2. You can now manage your AWS resources directly from your WSL2 terminal. Remember to secure your AWS credentials and follow best practices for IAM users and permissions.