How to Install and Configure AWS CLI: Complete Guide
By Braincuber Team
Published on April 10, 2026
The AWS Command Line Interface (CLI) is an essential tool for managing your Amazon Web Services resources efficiently from the terminal. Whether you are automating infrastructure, querying resource data, or managing CloudFormation stacks, the AWS CLI gives you programmatic access to your entire AWS environment. This complete tutorial walks you through installing AWS CLI v2, configuring authentication, and using powerful commands to understand your resource environment.
What You'll Learn:
- How to install AWS CLI v2 on Linux, macOS, and Windows
- Step by step guide to configuring AWS CLI with access keys
- How to use AWS CLI to list and understand your resources
- Beginner guide to CloudFormation stack management via CLI
- How to query EC2 instances, VPCs, and subnets with filters
- Complete tutorial on using --query and --filters for output formatting
What is AWS CLI?
The AWS Command Line Interface is a unified tool that provides commands for interacting with all AWS services from your terminal. AWS CLI v2 is the current major version, offering improved performance, new features, and automatic updates. Once configured, you can manage everything from S3 buckets to EC2 instances, Lambda functions to RDS databases, all without leaving your command line.
Automation
Script repetitive tasks and automate infrastructure management using shell scripts or CI/CD pipelines.
Speed
Execute commands instantly without navigating through the AWS Management Console web interface.
Infrastructure as Code
Deploy and manage CloudFormation stacks directly from JSON templates using the CLI.
Resource Discovery
Query and understand your entire AWS resource environment with describe commands.
How to Install AWS CLI v2
Installing AWS CLI v2 is straightforward. The best approach is to follow the official AWS installation guide for your operating system. AWS currently recommends v2, and there are no compelling reasons to use v1 anymore.
Installation on Linux
For Linux systems, download the AWS CLI v2 package using curl, unzip it, and run the installation script with sudo privileges.
Install AWS CLI on Linux
Run the following commands in your Linux terminal to download, extract, and install AWS CLI v2:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version
Installation on macOS
On macOS, you can use the bundled installer or Homebrew. The bundled installer approach is recommended for consistency.
curl "https://awscli.amazonaws.com/awscli-exe-macos.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version
Installation on Windows
For Windows, download and run the MSI installer from the AWS documentation website, or use the MSI installer via command line.
msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi
Note
After installation, run aws --version to confirm AWS CLI v2 is installed correctly. You should see output like aws-cli/2.x.x.
How to Configure AWS CLI
To authenticate the CLI to your AWS account, you need valid access keys. You cannot use the create-access-key command without first authenticating, which creates a chicken-and-egg problem. Instead, access your security credentials from the AWS Management Console.
Get AWS Access Keys from Console
Step by step guide to obtaining your access keys:
- Sign in to AWS Management Console
- Click your account name in the top navigation
- Select "Security Credentials" from the dropdown
- Expand "Access keys" section
- Click "Create New Access Key"
- Download or copy the Access Key ID and Secret Access Key
Running aws configure
With your credentials in hand, run the aws configure command. You will be prompted to enter your Access Key ID and Secret Access Key. You can also choose a default AWS region and output format, though the default JSON format works well for most use cases.
aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-east-1
Default output format [None]: json
Verify Configuration
To confirm everything is working, list all S3 buckets in your account. This simple command verifies your credentials and connectivity.
aws s3 ls
Understanding Your AWS Resource Environment
Amazon CloudFormation lets you manage your application infrastructure by organizing AWS resources into stacks. CloudFormation templates can define complete environments including VPCs, subnets, EC2 instances, RDS databases, and more. While you can manage stacks through the AWS Management Console, using the AWS CLI provides powerful scripting capabilities.
Describe VPCs
VPCs (Virtual Private Clouds) are fundamental networking containers for your AWS resources. To get information about your VPCs, use the describe-vpcs command. This returns all VPC data including VPC IDs, CIDR blocks, and states.
aws ec2 describe-vpcs
Describe Subnets
Subnets are subdivisions of your VPC that contain your compute resources. Use describe-subnets to list all subnets and their associated VPC IDs, availability zones, and CIDR blocks.
aws ec2 describe-subnets
Working with CloudFormation Stacks
CloudFormation templates define your infrastructure as code. You can create stacks using the create-stack command. A minimal example requires the template file, stack name, and SSH key pair.
Create a CloudFormation Stack
Step by step guide to launching a stack with CloudFormation:
- Download or create a CloudFormation template (JSON format)
- Use create-stack command with required parameters
- Specify template-body with file path
- Provide stack name
- Add parameters for VPC, subnets, database credentials
- Wait for stack creation (can take 15-30 minutes)
aws cloudformation create-stack --template-body file://lamp-as.json --stack-name lamp --parameters ParameterKey=KeyName,ParameterValue=mykey
Important Syntax Tips
When passing multiple subnet IDs, separate them with commas but no spaces, and enclose in single quotes escaped with backslashes. Also ensure parameter keys use lowercase "Id" (like VpcId), not VpcID - case sensitivity matters!
Full Stack Creation Example
Here is a complete example with VPC, subnets, and database parameters for a multi-AZ LAMP stack deployment.
aws cloudformation create-stack --template-body file://lamp-as.json --stack-name lamp-as --parameters ParameterKey=KeyName,ParameterValue=mykey ParameterKey=VpcId,ParameterValue=vpc-1ffbc964 ParameterKey=Subnets,ParameterValue='subnet-0e170b31,subnet-52d6117c' ParameterKey=DBUser,ParameterValue=myadmin ParameterKey=DBPassword,ParameterValue=mypass23
Describe EC2 Instances
The describe-instances command provides detailed information about your EC2 instances. You can filter results to show only running instances and use the --query option to extract specific fields.
aws ec2 describe-instances --filters Name=instance-state-name,Values=running --query 'Reservations[*].Instances[*].{Instance:InstanceId,PublicIPAddress:PublicIpAddress}'
Describe CloudFormation Stacks
Once your CloudFormation stack is created (which can take up to 30 minutes), you can check its status and get the website URL using describe-stacks.
aws cloudformation describe-stacks
Essential AWS CLI Commands Reference
| Command | Description |
|---|---|
| aws s3 ls | List all S3 buckets |
| aws ec2 describe-vpcs | List all VPCs in region |
| aws ec2 describe-subnets | List all subnets |
| aws ec2 describe-instances | List all EC2 instances |
| aws lambda list-functions | List all Lambda functions |
| aws rds describe-db-instances | List all RDS databases |
| aws cloudformation describe-stacks | List all CloudFormation stacks |
| aws iam list-users | List all IAM users |
Frequently Asked Questions
What is the difference between AWS CLI v1 and v2?
AWS CLI v2 is the current major version with improved performance, automatic updates via MSI/PKG installers, and new features. v1 is deprecated. AWS recommends using v2 for all new installations.
How do I configure multiple AWS profiles?
Use aws configure --profile profilename to create named profiles. Then specify which profile to use with --profile profilename in your commands or set AWS_PROFILE environment variable.
Why is my AWS CLI returning "Unable to locate credentials"?
Run aws configure to set up your Access Key ID and Secret Access Key. Ensure your credentials are stored in ~/.aws/credentials (Linux/macOS) or %UserProfile%.awscredentials (Windows).
How do I filter AWS CLI output to show specific fields?
Use the --query parameter with JMESPath syntax to filter output. For example: --query 'Reservations[*].Instances[*].InstanceId' to show only instance IDs.
How long does a CloudFormation stack take to create?
Stack creation typically takes 5-30 minutes depending on complexity. Simple stacks may complete in minutes, while complex multi-resource stacks with RDS databases can take 15-30 minutes or longer.
Need Help with AWS CLI Setup?
AWS CLI is powerful for automating cloud operations, but configuring it correctly for your infrastructure needs expertise. We help businesses set up AWS CLI, manage CloudFormation templates, and automate their cloud operations. From initial configuration to advanced infrastructure automation, we have the expertise to help you succeed.
