A Beginner’s Guide to Working with AWS CLI

In this blog, discover the power of Amazon Web Services (AWS) Command Line Interface (CLI) as we guide you through its setup and usage. Efficiently manage your AWS environment directly from the terminal with ease. and learn more about working with AWS CLI.

Installing the AWS CLI

Step 1: Prerequisites Before installing the AWS CLI, ensure you have the following prerequisites:

  • An AWS account: Sign up for a free AWS account if you don’t have one.
  • An access key ID and secret access key: Generate these in the AWS Management Console under the IAM (Identity and Access Management) service.

Step 2: Installation

For Windows Users:

  • Download the AWS CLI MSI installer from the AWS website.
  • Run the installer and follow the installation wizard’s instructions.
  • After installation, open a new command prompt to use the AWS CLI.

Note : For windows installation please refer this link (

For macOS and Linux Users:

  • On macOS, you can use Homebrew:
brew install awscli
  • On Linux, use your package manager. For example, on Ubuntu/Debian:
sudo apt-get update
sudo apt-get install awscli

Step 3: Configure AWS CLI

Open a terminal or command prompt. Run the following command:

aws configure
AWS configured

Enter your AWS access key ID, secret access key, default region (e.g., us-east-1), and default output format (e.g., json).

Basic AWS CLI Commands

Step 1: Verify Configuration To verify your AWS CLI configuration, run the following command:

aws configure list
AWS Configurations List

This will display your current AWS CLI configuration settings.

Step 2: Listing AWS Resources To list AWS resources, use the appropriate AWS CLI command along with the resource type. For example, to list EC2 instances:

aws ec2 describe-instances

Step 3: Creating AWS Resources To create AWS resources, use the create commands followed by the resource type and required parameters. For example, to create an S3 bucket:

aws s3api create-bucket --bucket my-bucket-name --region us-east-1

Step 4: Managing AWS Resources To manage resources, use the update and delete commands along with the resource type and relevant parameters. For example, to update an EC2 instance’s security group:

aws ec2 modify-instance-attribute --instance-id i-1234567890abcdef0 --groups sg-12345678

Section 3: Tips and Best Practices

  1. Use --help: For any AWS CLI command, you can use the --help flag to display information about the command’s options and parameters.
  2. AWS CLI Profiles: If you have multiple AWS accounts or roles, consider using AWS CLI profiles to manage different configurations.
  3. Output Formats: By default, the AWS CLI outputs information in JSON format. However, you can use other formats like text, table, or yaml based on your preference.
  4. Automating with Scripts: The AWS CLI is scriptable, making it ideal for automating repetitive tasks and integrating AWS management with other tools and scripts.

AWS CLI Profiles and Configuration Options

AWS CLI profiles are a powerful feature that allows users to manage multiple AWS accounts and roles efficiently. When working with different AWS environments, such as development, staging, and production, or when collaborating with different teams, using profiles can simplify the configuration process. Let’s explore how to set up and use AWS CLI profiles.

Step 1: Configuring AWS CLI Profiles 

To create a new profile, use the “aws configure” command with the “ — profile” flag, followed by the profile name. For example, to create a profile for a development environment:

aws configure --profile development

You will be prompted to enter the access key ID, secret access key, default region, and output format specific to the development environment. Repeat this process for each profile you want to create.

Step 2: Using AWS CLI

Profiles Once you have set up multiple profiles, you can specify which profile to use for each AWS CLI command using the “ — profile” flag. For instance, to list S3 buckets in the development environment, you can run:

aws s3api list-buckets --profile development

Similarly, to create a new EC2 instance in the production environment, you can use:

aws ec2 run-instances --instance-type t2.micro --image-id ami-0c55b159cbfafe1f0 --count 1 --profile production

Using profiles, you can easily switch between different AWS accounts and configurations without having to re-enter access credentials each time.

Advanced AWS CLI Commands and Use Cases

AWS CLI offers a plethora of advanced commands and features that cater to various use cases. Let’s delve into some of these advanced use cases.

Working with AWS CloudFormation, CloudFormation is AWS’s Infrastructure as Code (IaC) service. The AWS CLI allows you to create, update, and delete CloudFormation stacks from the command line. For example, to create a stack:

aws cloudformation create-stack --stack-name my-stack --template-body file://template.yaml

Managing AWS Identity and Access Management (IAM) IAM is AWS’s identity management service. With the AWS CLI, you can manage IAM users, roles, and policies easily. For example, to create an IAM user:

aws iam create-user --user-name my-user

Interacting with AWS DynamoDB DynamoDB is AWS’s managed NoSQL database service. The AWS CLI allows you to perform operations such as putting items, querying data, and managing tables. For example, to put an item into a DynamoDB table:

aws dynamodb put-item --table-name my-table --item '{"id": {"S": "1"}, "name": {"S": "John Doe"}}'

Copying Data to and from AWS S3 S3 is AWS’s object storage service. The AWS CLI enables you to transfer data to and from S3 buckets easily. For example, to copy a file from your local machine to an S3 bucket:

aws s3 cp my-file.txt s3://my-bucket/

Wrapping Up

By using the AWS CLI you have the ability to unlock all the capabilities of Amazon Web Services directly from your command line. In this manual we’ve discussed the steps, for setting up configuring and utilizing the AWS CLI to effectively handle AWS resources. With this information in hand you can delve into AWS CLI instructions and automate intricate AWS tasks to simplify your cloud management process. Wishing you a smooth journey, with AWS CLI!

This website stores cookies on your computer. Cookie Policy