Installing and Configuring the AWS CLI
The console is great for exploration and one-off tasks, but production work demands automation. The AWS Command Line Interface (CLI) is a unified tool that gives you command-line access to AWS services. If you can click it in the console, you can script it with the CLI.
Installation varies by platform. On Windows, download the MSI installer from AWS or use winget install Amazon.AWSCLI. On macOS, use brew install awscli. On Linux, use your package manager (apt, yum, dnf) or install from the bundled installer. After installation, verify with aws --version. AWS CLI v2 is the current major version; v1 is legacy.
Configuration requires three credentials: your Access Key ID, Secret Access Key, and default region. Run aws configure to set these up interactively. The credentials are stored in ~/.aws/credentials and the config in ~/.aws/config. For security best practices, never commit these files to version control.
You can create access keys in the IAM console under Security Credentials. Each user can have two active access keys at a time. Rotate keys regularly and delete unused ones. For enhanced security, use IAM roles instead of long-lived access keys whenever possible. If you are running CLI commands from an EC2 instance, the instance can assume an IAM role, eliminating the need for stored credentials.
Profiles let you manage multiple AWS accounts or regions from a single machine. Create named profiles with aws configure --profile production and aws configure --profile staging. Then use --profile flag with any command to target a specific account. This is essential for engineers managing dev, staging, and production environments.
Essential CLI Commands for EC2, S3, and IAM
The AWS CLI follows a consistent syntax: aws [service] [command] [options]. Here are the essential commands for the three foundational services.
EC2 Commands manage your virtual servers. aws ec2 describe-instances lists all instances with their state, IP addresses, and tags. aws ec2 run-instances launches a new instance with specified AMI, instance type, and key pair. aws ec2 stop-instances and aws ec2 start-instances control instance lifecycle. aws ec2 terminate-instances permanently deletes an instance. aws ec2 create-security-group and aws ec2 authorize-security-group-ingress manage network firewall rules. Always filter by region with --region flag if not configured as default.
S3 Commands manage object storage. aws s3 ls lists buckets. aws s3 mb s3://my-bucket-name creates a bucket. aws s3 cp file.txt s3://my-bucket/ uploads a file. aws s3 sync ./local-folder s3://my-bucket/ synchronizes a local directory with a bucket (only uploads changed files). aws s3 rm s3://my-bucket/file.txt deletes an object. aws s3api put-bucket-policy sets access policies. S3 is the workhorse of AWS storage; mastering these commands is essential.
IAM Commands manage access. aws iam list-users shows all users. aws iam create-user --user-name alice creates a new user. aws iam create-access-key --user-name alice generates credentials for a user. aws iam put-user-policy attaches an inline policy. aws iam create-group and aws iam add-user-to-group manage team access. aws iam list-roles shows service roles. Always follow the principle of least privilege; grant only the permissions needed for the specific task.
The CLI supports output formatting with --output table, --output json, and --output text flags. Use --query parameter with JMESPath expressions to filter results. For example, aws ec2 describe-instances --query Reservations[].Instances[].[InstanceId,State.Name,PublicIpAddress] --output table shows a clean table of instance IDs, states, and public IPs.
Console vs CLI: When to Use Which
The console and CLI solve different problems. Knowing when to use each is a practical skill that improves your efficiency.
Use the console when you are exploring unfamiliar services, visually debugging resource configurations, or performing one-off administrative tasks. The console excels at discovery; you can browse service options, see visual dashboards, and understand resource relationships at a glance. The billing dashboard, CloudWatch metrics graphs, and VPC network diagrams are all console-native experiences that have no CLI equivalent. The console is also better for tasks that benefit from visual feedback, such as building IAM policies with the visual editor or configuring Auto Scaling groups with the scaling policy wizard.
Use the CLI when you are automating repetitive tasks, scripting infrastructure provisioning, integrating with CI/CD pipelines, or debugging in environments without browser access (like SSH sessions on remote servers). The CLI is deterministic; the same command produces the same result every time. This makes it ideal for automation and reproducibility. You can chain CLI commands in shell scripts, pipe output to other tools, and version control your infrastructure commands.
Infrastructure as Code (IaC) goes beyond the CLI. Tools like AWS CloudFormation, Terraform, and AWS CDK define your infrastructure in code files. IaC is declarative: you describe the desired end state, and the tool figures out how to create it. This is the professional standard for cloud management. The CLI is imperative; you specify each action step by step. IaC is declarative; you specify what you want, and the tool makes it happen.
The practical workflow for most cloud engineers combines both. Use the console for initial exploration and visual verification. Use the CLI for quick commands and scripting. Use IaC for production infrastructure management. A typical day might involve checking costs in the console, running a CLI command to restart a stuck instance, and editing a Terraform file to add a new service. Master all three; each has its place.
Quiz
1. What is the first thing you should set up for console security?
2. Which CLI command synchronizes a local directory with an S3 bucket, uploading only changed files?
3. Where does the AWS CLI store credentials after running aws configure?
4. When should you use Infrastructure as Code (IaC) instead of CLI commands?
Flashcards
Question
What is the AWS Management Console?
Click to reveal answer
Answer
A web-based interface for managing AWS resources. Best for exploration, visual debugging, and one-off tasks.
Question
What does aws configure do?
Click to reveal answer
Answer
Sets up your AWS CLI with Access Key ID, Secret Access Key, default region, and output format. Credentials are stored in ~/.aws/credentials.
Question
What is the difference between aws s3 cp and aws s3 sync?
Click to reveal answer
Answer
cp copies individual files. sync synchronizes entire directories, uploading only changed files. sync is more efficient for bulk operations.
Question
What is Infrastructure as Code (IaC)?
Click to reveal answer
Answer
Defining infrastructure in code files (CloudFormation, Terraform) rather than manual CLI commands. It is declarative, reproducible, and version-controlled.
Revision Notes
Key Takeaways
- 1. The AWS Console is best for exploration, visual debugging, and one-off tasks
- 2. The AWS CLI is best for automation, scripting, and CI/CD integration
- 3. Always create an IAM admin user with MFA; never use the root account for daily operations
- 4. AWS CLI follows the syntax: aws [service] [command] [options] with consistent patterns across services
- 5. Infrastructure as Code (CloudFormation, Terraform) is the professional standard for production infrastructure management
Interview Tips
- • Demonstrate you know both console and CLI workflows; mention when you would use each
- • Know the IAM security basics: root account, MFA, least privilege, access key rotation
- • Be ready to give examples of CLI commands for EC2, S3, and IAM
- • Explain the progression from console to CLI to IaC as maturity increases
Cheat Sheet
Console = web UI for exploration. CLI = command-line for automation. IaC = code for production. aws configure sets up credentials. aws s3 sync for directory sync. aws ec2 describe-instances for listing VMs. Always use IAM admin, never root.