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
CLI scripting basics
📖 Scenario: You are managing a small cloud environment on AWS. You want to automate the process of listing your EC2 instances and filtering them by a specific tag using AWS CLI commands in a script.
🎯 Goal: Create a simple AWS CLI script that lists all EC2 instances, filters them by a tag named Environment with the value Development, and outputs the instance IDs.
📋 What You'll Learn
Use AWS CLI commands to list EC2 instances
Filter instances by the tag Environment with value Development
Extract and output only the instance IDs
💡 Why This Matters
🌍 Real World
Automating AWS resource management using CLI scripts saves time and reduces errors in cloud operations.
💼 Career
Cloud engineers and DevOps professionals often write CLI scripts to manage and automate cloud infrastructure efficiently.
Progress0 / 4 steps
1
Create a variable with the AWS CLI command to list all EC2 instances
Create a variable called list_instances_cmd and assign it the AWS CLI command string aws ec2 describe-instances.
AWS
Hint
Assign the exact string aws ec2 describe-instances to the variable list_instances_cmd.
2
Add a filter variable for the tag Environment=Development
Create a variable called filter_tag and assign it the AWS CLI filter string --filters Name=tag:Environment,Values=Development.
AWS
Hint
Use the exact filter string with --filters Name=tag:Environment,Values=Development.
3
Combine the command and filter to list filtered instances
Create a variable called filtered_cmd that combines list_instances_cmd and filter_tag separated by a space.
AWS
Hint
Join the two strings with a space between them.
4
Add the query to output only instance IDs
Update the variable final_cmd by adding the query option --query 'Reservations[].Instances[].InstanceId' --output text to filtered_cmd separated by a space.
AWS
Hint
Append the exact query and output options to the filtered command string.
Practice
(1/5)
1. What does the AWS CLI command aws s3 ls do?
easy
A. Deletes all S3 buckets in your AWS account
B. Creates a new S3 bucket
C. Lists all S3 buckets in your AWS account
D. Uploads a file to an S3 bucket
Solution
Step 1: Understand the command structure
The command uses aws s3 which relates to the S3 service, and ls which means list.
Step 2: Interpret the command action
Listing in S3 context means showing all buckets or objects. Without extra parameters, it lists all buckets.
Final Answer:
Lists all S3 buckets in your AWS account -> Option C
Quick Check:
Command aws s3 ls lists buckets [OK]
Hint: Remember: 'ls' means list, so it shows existing resources [OK]
Common Mistakes:
Confusing 'ls' with 'rm' (delete)
Thinking it creates resources
Assuming it uploads files
2. Which of the following is the correct syntax to create an EC2 instance using AWS CLI?
easy
A. aws ec2 run-instances --image-id ami-12345678 --count 1
B. aws ec2 create-instance --image-id ami-12345678 --count 1
C. aws ec2 start-instance --image-id ami-12345678 --count 1
D. aws ec2 launch-instance --image-id ami-12345678 --count 1
Solution
Step 1: Identify the correct AWS CLI command for EC2 instance creation
The official command to create EC2 instances is run-instances.
Step 2: Check the syntax correctness
aws ec2 run-instances --image-id ami-12345678 --count 1 uses aws ec2 run-instances --image-id ami-12345678 --count 1, which is the correct syntax to launch one instance.
Final Answer:
aws ec2 run-instances --image-id ami-12345678 --count 1 -> Option A