Bird
Raised Fist0
AWScloud~10 mins

CLI scripting basics in AWS - Interactive Code Practice

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
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to list all S3 buckets using AWS CLI.

AWS
aws s3 [1]
Drag options to blanks, or click blank then click option'
Acreate-bucket
Bdelete-bucket
Cls
Dput-object
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'create-bucket' instead of 'ls' will try to create a bucket.
Using 'delete-bucket' will attempt to remove a bucket, not list them.
2fill in blank
medium

Complete the code to create a new S3 bucket named 'my-bucket' in the us-west-2 region.

AWS
aws s3api create-bucket --bucket my-bucket --region us-west-2 --[1] LocationConstraint=us-west-2
Drag options to blanks, or click blank then click option'
Ainput
Bcreate-bucket-configuration
Coutput
Dcreate
Attempts:
3 left
💡 Hint
Common Mistakes
Using '--output' or '--input' does not set the bucket region.
Using '--create' is not a valid AWS CLI option.
3fill in blank
hard

Fix the error in the command to copy a file named 'photo.jpg' to the S3 bucket 'my-bucket'.

AWS
aws s3 cp [1] s3://my-bucket/
Drag options to blanks, or click blank then click option'
Aphotojpeg
Bphoto
Cphoto.png
Dphoto.jpg
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the file extension causes the command to fail.
Using a wrong file extension like '.png' or misspelled name.
4fill in blank
hard

Fill both blanks to list all EC2 instances in the 'us-west-2' region with detailed information.

AWS
aws ec2 [1] --region [2] --output json
Drag options to blanks, or click blank then click option'
Adescribe-instances
Bus-east-1
Cus-west-2
Dlist-instances
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'list-instances' is not a valid AWS CLI command.
Setting the wrong region will show no instances or error.
5fill in blank
hard

Fill all three blanks to create a new IAM user named 'developer' with programmatic access and attach the 'AmazonS3ReadOnlyAccess' policy.

AWS
aws iam create-user --user-name [1] && aws iam create-access-key --user-name [2] && aws iam attach-user-policy --user-name [3] --policy-arn arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
Drag options to blanks, or click blank then click option'
Aadmin
Bdeveloper
Cuser
Dreadonly
Attempts:
3 left
💡 Hint
Common Mistakes
Using different user names in each command causes errors.
Using generic names like 'admin' or 'user' instead of 'developer'.

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

  1. Step 1: Understand the command structure

    The command uses aws s3 which relates to the S3 service, and ls which means list.
  2. Step 2: Interpret the command action

    Listing in S3 context means showing all buckets or objects. Without extra parameters, it lists all buckets.
  3. Final Answer:

    Lists all S3 buckets in your AWS account -> Option C
  4. 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

  1. Step 1: Identify the correct AWS CLI command for EC2 instance creation

    The official command to create EC2 instances is run-instances.
  2. 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.
  3. Final Answer:

    aws ec2 run-instances --image-id ami-12345678 --count 1 -> Option A
  4. Quick Check:

    EC2 instance creation uses 'run-instances' command [OK]
Hint: Use 'run-instances' to launch EC2, not 'create-instance' [OK]
Common Mistakes:
  • Using 'create-instance' which is invalid
  • Confusing 'start-instance' with creation
  • Using 'launch-instance' which is not a valid command
3. What will be the output of this AWS CLI command?
aws s3api list-buckets --query 'Buckets[].Name' --output json
medium
A. A JSON array of bucket names
B. A list of bucket creation dates
C. An error because of wrong syntax
D. A plain text list of bucket names

Solution

  1. Step 1: Understand the command components

    The command uses list-buckets to get all buckets, with a query to extract only the bucket names.
  2. Step 2: Analyze the output format

    The --output json option formats the result as JSON, so the output is a JSON array of bucket names.
  3. Final Answer:

    A JSON array of bucket names -> Option A
  4. Quick Check:

    Query filters names, output json formats as JSON array [OK]
Hint: Query filters data, output json formats it as JSON [OK]
Common Mistakes:
  • Expecting plain text instead of JSON
  • Confusing bucket names with creation dates
  • Assuming syntax error due to query
4. You run this command to delete an S3 bucket:
aws s3 rb s3://my-bucket

But it fails with an error. What is the most likely cause?
medium
A. You need to use aws s3 rm instead
B. The bucket is not empty
C. The bucket name is invalid
D. The AWS CLI is not installed

Solution

  1. Step 1: Understand the command purpose

    aws s3 rb removes (deletes) an S3 bucket, but only if it is empty.
  2. Step 2: Identify the common error cause

    If the bucket contains files, the command fails. You must delete all objects first.
  3. Final Answer:

    The bucket is not empty -> Option B
  4. Quick Check:

    Bucket must be empty before removal [OK]
Hint: Empty bucket before deleting with 'rb' command [OK]
Common Mistakes:
  • Trying to delete non-empty bucket directly
  • Confusing 'rm' (remove objects) with 'rb' (remove bucket)
  • Assuming AWS CLI is not installed without checking
5. You want to write a script that lists all EC2 instances and then stops each one. Which AWS CLI commands should you combine in the script?
hard
A. Use aws ec2 show-instances to list, then aws ec2 power-off-instances to stop
B. Use aws ec2 list-instances to list, then aws ec2 terminate-instances to stop
C. Use aws ec2 get-instances to list, then aws ec2 shutdown-instances to stop
D. Use aws ec2 describe-instances to list, then aws ec2 stop-instances --instance-ids to stop

Solution

  1. Step 1: Identify the correct command to list EC2 instances

    The correct command to list instances is describe-instances.
  2. Step 2: Identify the correct command to stop instances

    To stop instances, use stop-instances with the instance IDs.
  3. Step 3: Combine commands in script logic

    First list instances to get IDs, then stop them using those IDs.
  4. Final Answer:

    Use aws ec2 describe-instances to list, then aws ec2 stop-instances --instance-ids to stop -> Option D
  5. Quick Check:

    List with describe, stop with stop-instances [OK]
Hint: List with 'describe-instances', stop with 'stop-instances' [OK]
Common Mistakes:
  • Using non-existent commands like 'list-instances'
  • Confusing 'terminate' with 'stop' (termination deletes)
  • Using wrong commands that cause errors