Bird
Raised Fist0
AWScloud~10 mins

Basic CLI commands (s3, ec2) in AWS - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Process Flow - Basic CLI commands (s3, ec2)
Start: Open Terminal
Type AWS CLI command
CLI sends request to AWS service
AWS service processes request
Receive response in terminal
View output or error message
Repeat or exit
The flow shows how a user types AWS CLI commands for S3 or EC2, the commands are sent to AWS, processed, and the results appear in the terminal.
Execution Sample
AWS
aws s3 ls
aws ec2 describe-instances
List S3 buckets and then list EC2 instances using AWS CLI commands.
Process Table
StepCommand EnteredAWS Service ContactedAction TakenOutput Shown
1aws s3 lsS3List all S3 buckets in accountDisplays list of bucket names
2aws ec2 describe-instancesEC2Retrieve details of EC2 instancesShows instance IDs, states, and info
3exit or no commandNoneEnd session or no actionTerminal ready for next command or closed
💡 User stops entering commands or closes terminal, ending the CLI session.
Status Tracker
VariableStartAfter Step 1After Step 2Final
CommandNoneaws s3 lsaws ec2 describe-instancesNone
Service ContactedNoneS3EC2None
OutputNoneList of bucketsList of EC2 instancesNone
Key Moments - 2 Insights
Why does the command 'aws s3 ls' show bucket names and not files inside a bucket?
Because 'aws s3 ls' without a bucket name lists all buckets. To see files, you must specify a bucket like 'aws s3 ls s3://bucket-name'. See execution_table step 1 where only buckets are listed.
What happens if you run 'aws ec2 describe-instances' but have no EC2 instances?
The command runs successfully but returns an empty list. The output shows no instances, as in execution_table step 2, the output depends on existing resources.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what AWS service is contacted when running 'aws s3 ls'?
AS3
BEC2
CLambda
DCloudWatch
💡 Hint
Check the 'AWS Service Contacted' column in execution_table row 1.
At which step does the CLI show details about EC2 instances?
AStep 1
BStep 3
CStep 2
DNo step shows EC2 details
💡 Hint
Look at the 'Output Shown' column for EC2 instance details in execution_table.
If you want to see files inside a specific S3 bucket, how would the command change?
Aaws s3 ls
Baws s3 ls s3://bucket-name
Caws ec2 describe-instances
Daws s3 cp
💡 Hint
Refer to key_moments explanation about listing files inside a bucket.
Concept Snapshot
AWS CLI commands let you control AWS services from the terminal.
Use 'aws s3 ls' to list buckets.
Use 'aws s3 ls s3://bucket-name' to list files in a bucket.
Use 'aws ec2 describe-instances' to see EC2 instances.
Commands send requests to AWS and show results in the terminal.
Full Transcript
This lesson shows how basic AWS CLI commands work for S3 and EC2. You start by opening a terminal and typing commands like 'aws s3 ls' to list buckets or 'aws ec2 describe-instances' to see EC2 instances. The CLI sends these commands to AWS services, which process them and return results shown in the terminal. For example, 'aws s3 ls' lists all your S3 buckets, but to see files inside a bucket, you must specify the bucket name. Similarly, 'aws ec2 describe-instances' shows details about your EC2 virtual machines. The execution table traces these steps, showing commands entered, services contacted, actions taken, and outputs. Key moments clarify common confusions, like why bucket names appear instead of files. The visual quiz tests your understanding by asking about services contacted and command outputs. This helps you learn how to use AWS CLI commands effectively to manage cloud resources.

Practice

(1/5)
1. Which AWS CLI command lists all buckets in Amazon S3?
easy
A. aws s3 list-buckets
B. aws ec2 ls
C. aws ec2 describe-buckets
D. aws s3 ls

Solution

  1. Step 1: Understand the service for buckets

    Amazon S3 stores buckets, so the command must use aws s3.
  2. Step 2: Identify the correct action to list buckets

    The ls action lists buckets in S3. So aws s3 ls lists all buckets.
  3. Final Answer:

    aws s3 ls -> Option D
  4. Quick Check:

    List buckets = aws s3 ls [OK]
Hint: Use 'aws s3 ls' to list buckets quickly [OK]
Common Mistakes:
  • Confusing EC2 commands with S3 commands
  • Using 'list-buckets' which is not a valid CLI action
  • Trying to list buckets with 'aws ec2' commands
2. Which command correctly starts an EC2 instance with ID i-1234567890abcdef0?
easy
A. aws ec2 start-instances --instance-ids i-1234567890abcdef0
B. aws ec2 start-instance --instance-ids i-1234567890abcdef0
C. aws ec2 start-instances --instance-id i-1234567890abcdef0
D. aws ec2 start-instance --instance-id i-1234567890abcdef0

Solution

  1. Step 1: Identify the correct EC2 start command

    The correct command to start instances is start-instances (plural).
  2. Step 2: Use the correct option name for instance IDs

    The option is --instance-ids (plural), not --instance-id.
  3. Final Answer:

    aws ec2 start-instances --instance-ids i-1234567890abcdef0 -> Option A
  4. Quick Check:

    Start instances = start-instances + --instance-ids [OK]
Hint: Use plural 'start-instances' and '--instance-ids' options [OK]
Common Mistakes:
  • Using singular 'start-instance' instead of 'start-instances'
  • Using '--instance-id' instead of '--instance-ids'
  • Mixing up EC2 and S3 commands
3. What is the output of this command if the bucket my-bucket contains two files file1.txt and file2.txt?
aws s3 ls s3://my-bucket/
medium
A. Lists the names and sizes of file1.txt and file2.txt
B. Shows an error: bucket not found
C. Lists only the bucket name my-bucket
D. Deletes the files in the bucket

Solution

  1. Step 1: Understand the command purpose

    aws s3 ls s3://my-bucket/ lists objects inside the bucket my-bucket.
  2. Step 2: Predict the output for files in the bucket

    The command will show the file names and their sizes for file1.txt and file2.txt.
  3. Final Answer:

    Lists the names and sizes of file1.txt and file2.txt -> Option A
  4. Quick Check:

    List bucket contents = file names + sizes [OK]
Hint: Use 'aws s3 ls s3://bucket/' to list files inside [OK]
Common Mistakes:
  • Thinking it lists buckets instead of files
  • Expecting deletion or error output
  • Confusing bucket name listing with object listing
4. You run this command but get an error: aws ec2 describe-instances --instance-ids i-1234567890abcdef0. What is the likely cause?
medium
A. The command should be aws s3 describe-instances
B. The instance ID is incorrect or does not exist
C. You must use start-instances instead of describe-instances
D. You forgot to add --bucket option

Solution

  1. Step 1: Check command correctness

    aws ec2 describe-instances --instance-ids is a valid command to get instance details.
  2. Step 2: Identify common error reasons

    An error usually means the instance ID is wrong or the instance does not exist in your account or region.
  3. Final Answer:

    The instance ID is incorrect or does not exist -> Option B
  4. Quick Check:

    Invalid instance ID causes describe-instances error [OK]
Hint: Check instance ID spelling and region for describe-instances errors [OK]
Common Mistakes:
  • Using S3 commands for EC2 tasks
  • Confusing describe with start commands
  • Adding irrelevant options like --bucket
5. You want to copy a local file photo.jpg to an S3 bucket my-photos in a folder 2024/. Which command correctly does this?
hard
A. aws ec2 cp photo.jpg s3://my-photos/2024/
B. aws s3 mv photo.jpg s3://my-photos/2024/
C. aws s3 cp photo.jpg s3://my-photos/2024/
D. aws s3 sync photo.jpg s3://my-photos/2024/

Solution

  1. Step 1: Choose the correct AWS service and action

    Copying files to S3 uses aws s3 cp. EC2 commands do not handle S3 files.
  2. Step 2: Use the correct source and destination syntax

    Source is local file photo.jpg, destination is S3 path s3://my-photos/2024/.
  3. Final Answer:

    aws s3 cp photo.jpg s3://my-photos/2024/ -> Option C
  4. Quick Check:

    Copy local file to S3 = aws s3 cp [OK]
Hint: Use 'aws s3 cp' to copy files to S3 buckets [OK]
Common Mistakes:
  • Using 'mv' which moves instead of copies
  • Using 'sync' for single file copy
  • Using EC2 commands for S3 file operations