AWS Command Line Interface (CLI) : Install and Configure

Yasholo
5 min readMay 10, 2024

--

The Amazon Web Services (AWS) Command Line Interface (CLI) is a powerful tool that enables users to interact with various AWS services directly from the command line. Whether you’re a seasoned developer, sysadmin, or just starting your journey with AWS, mastering the AWS CLI can significantly enhance your productivity and efficiency.

You can perform various tasks such as creating and managing instances, configuring security groups, managing S3 buckets, and much more. It’s quite handy for automating tasks and integrating AWS services into your scripts or workflows.

Why use AWS CLI?

The AWS Command Line Interface (CLI) provides numerous benefits, making it a valuable tool for developers, system administrators, and DevOps engineers working with Amazon Web Services (AWS). Here are some key advantages of using the AWS CLI:

  1. Efficiency: The AWS CLI enables users to interact with AWS services directly from the command line, allowing for rapid execution of commands and tasks without the need to navigate through the AWS Management Console. This streamlines workflows and saves time, especially for repetitive or batch operations.
  2. Scripting and Automation: With the AWS CLI, users can script repetitive tasks and automate workflows, This automation capability enhances productivity, reduces manual errors, and facilitates the creation of robust and scalable infrastructure. By integrating the CLI with shell scripts, batch files, or automation pipelines, users can orchestrate complex deployments and manage resources efficiently.
  3. Access to All AWS Services: The CLI provides access to virtually all AWS services, including compute, storage, networking, databases, machine learning, and more. This allows users to manage their entire AWS infrastructure from a single command-line interface.
  4. Portability: The AWS CLI is platform-independent and can be installed on Windows, macOS, and various Linux distributions. This portability allows users to work seamlessly across different operating systems and environments, ensuring consistency and flexibility in managing AWS resources.
  5. Security and Authentication: The AWS CLI supports IAM authentication and authorization, allowing users to securely manage access to AWS resources. Organizations can enforce security policies, implement least privilege principles, and maintain compliance with regulatory requirements.
  6. Cost Optimization: The CLI provides insights into resource usage and billing information, allowing users to monitor and optimize their AWS spending. By analyzing usage patterns and making informed decisions, organizations can optimize costs and maximize ROI.

Step for Installation:

Windows

  1. Visit the AWS CLI documentation page: AWS CLI Documentation
  2. Download the AWS CLI installer for Windows.
  3. Run the installer and follow the on-screen instructions.
  4. Verify installation by opening a command prompt and typing aws — version.

macOS:

  1. Open Terminal.
  2. Install the AWS CLI using Homebrew by running brew install awscli.
  3. Verify the installation by typing aws --version.

Linux:

  • Open a terminal.
  • Use the curl command to download aws cli package.
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscli.zip"

The -o option specifies the file name that the downloaded package is written to. ('awscli.zip' in this case)

  • Unzip the installer.

(If your Linux system doesn’t have a built-in unzip command, use 'sudo apt install unzip' to install it or use any similar tool to unzip package.)

sudo apt install unzip 
unzip awscli.zip
  • Install the AWS CLI by running the install program.
sudo ./aws/install
  • Confirm the installation with the following command.
aws --version

Sweet! AWS-CLI has been Installed successfully!

Step for Configuration:

  • First of all keep your AWS Credentials (your AWS Access Key ID and Secret Access Key) handy!

IAM > Security credentials > Create access key > Copy you access key and secret access key > done (You can download .csv file for future reference of access key and secret access key)

  • Now, open a terminal or command prompt.
  • Run aws configure
  • Enter your AWS Access Key ID and Secret Access Key when prompted. These can be obtained from the AWS Management Console under IAM (Identity and Access Management).
  • Specify a default region. This is the AWS region the CLI will use by default for commands. (press enter to use default settings)
  • Choose a default output format (e.g., json, text). JSON is recommended for scripting. (simply press enter to use default settings)

Yay! AWS-CLI has been configured successfully!

Basic AWS-CLI Commands:

Once you’ve installed and configured the AWS CLI, you can start using it to interact with AWS services. Here are a few basic commands to get you started:

  • List S3 Buckets:
aws s3 ls
  • List EC2 Instances:
aws ec2 describe-instances
  • Create an S3 Bucket (note: the bucket name should be unique):
aws s3 mb s3://my-bucket-name
  • Upload a File to S3:
aws s3 cp /path/to/local/file s3://my-bucket-name/
  • Create an EC2 Instance:
aws ec2 run-instances --image-id <image-id> --instance-type <instance-type> --key-name <key-name> --subnet-id <subnet-id>

These are just a few examples of the commands you can run with the AWS CLI. As you become more comfortable with the CLI, you can explore its full range of capabilities to manage a wide variety of AWS services directly from your command line interface.

Use the Official aws cli documentation to know about more commands.

(A tip: press ‘ctrl+f’ and type in the name of the aws service you want to use through the aws cli, it will help you easily locate and hover over the service to get the required commands and information.)

Thanks for reading along till the end! Have a good day/night :)

You can read the same article on Linkedin.

--

--