AWS CLI Tutorial: Installation, Configuration & Hands-on Commands

AWS Command Line Interface (AWS CLI) is a powerful tool that allows developers and DevOps engineers to manage AWS services directly from the terminal. Instead of relying on the AWS Management Console, you can perform tasks faster and automate them using simple commands.

What Is AWS CLI?

AWS Command Line Interface (AWS CLI) is a unified tool used to interact with AWS services using terminal commands. It allows you to manage resources like EC2, S3, IAM, Lambda, and more without opening the browser.

  • Manage AWS resources efficiently
  • Automate operations using scripts
  • Avoid human errors from console usage
  • Handle large workloads (like thousands of S3 files)

Why AWS CLI Matters

Relying only on the AWS Console becomes slow and difficult when handling:

  • Multiple environments (dev, stage, prod)
  • Large-scale S3 operations
  • Repetitive tasks like uploads, backups, cleanups

AWS CLI solves these issues by enabling tasks to be completed with a single command or through reusable automation scripts.

Installing AWS CLI

Below are installation methods for different operating systems:

Windows

aws --version
where aws

macOS

curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /
aws --version
which aws

Linux

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version
which aws

Configuring AWS CLI

To authenticate the CLI with your AWS account, follow these steps:

Step 1: Create IAM User

  • Go to IAM → Users → Create User
  • Add permissions (e.g., Developer group or AdministratorAccess for learning)
  • Generate Access Key and Secret Key

Step 2: Configure CLI

aws configure

Enter your credentials:

AWS Access Key ID: AKIAXXXXXXXXX
AWS Secret Access Key: xxxxxxxxxxxxx
Default region name: ap-south-1
Default output format: json

Hands-on S3 Commands

After configuration, you can directly manage S3 buckets.

List all S3 buckets

aws s3 ls

Create a new bucket

aws s3 mb s3://my-demo-bucket

Upload a file

aws s3 cp myfile.txt s3://my-demo-bucket/

List bucket contents

aws s3 ls s3://my-demo-bucket/

Upload entire folder

aws s3 cp myfolder s3://my-demo-bucket/ --recursive

Download folder

aws s3 cp s3://my-demo-bucket/logs ./logs --recursive

Delete a file

aws s3 rm s3://my-demo-bucket/myfile.txt

Delete bucket with all contents

aws s3 rm s3://my-demo-bucket --recursive
aws s3 rb s3://my-demo-bucket

Automation With Shell Scripts

AWS CLI becomes most powerful when paired with shell scripting.

Example Script: Create Bucket & Upload File

#!/bin/bash

BUCKET=my-automation-bucket-$RANDOM
echo "Creating bucket: $BUCKET"

aws s3 mb s3://$BUCKET

echo "Uploading file..."
aws s3 cp sample.txt s3://$BUCKET/

echo "Listing bucket contents:"
aws s3 ls s3://$BUCKET/

This converts manual AWS tasks into automated workflows. You can integrate such scripts into CI/CD pipelines or extend them using Terraform, CloudFormation, or CDK for full Infrastructure as Code.

Final Thoughts

AWS CLI is a foundational tool for cloud engineers and DevOps professionals. It improves speed, eliminates manual errors, and enables automation of large-scale AWS operations. Once you learn installation, configuration, S3 commands, and automation, you’re ready to build advanced workflows and cloud pipelines.

Comments

Popular posts from this blog

Spring Boot on AWS EC2: Upload to S3 Securely Using IAM Role

Java Streams Intermediate Operations Explained with Examples

ConcurrentHashMap vs Synchronized HashMap in Java