Bird
0
0

You want to automate starting all stopped EC2 instances using AWS CLI scripting. Which command sequence correctly lists stopped instances and starts them?

hard📝 Application Q9 of 15
AWS - CLI
You want to automate starting all stopped EC2 instances using AWS CLI scripting. Which command sequence correctly lists stopped instances and starts them?
Aaws ec2 describe-instances --filters Name=instance-state-name,Values=stopped --query 'Reservations[].Instances[].InstanceId' --output text | xargs -n1 aws ec2 start-instances --instance-ids
Baws ec2 start-instances --filters Name=instance-state-name,Values=stopped
Caws ec2 describe-instances --state stopped | aws ec2 start-instances
Daws ec2 start-instances --instance-ids $(aws ec2 list-stopped-instances)
Step-by-Step Solution
Solution:
  1. Step 1: List stopped instances using filters and query

    The command uses --filters to select stopped instances and --query to extract their IDs.
  2. Step 2: Use xargs to pass each instance ID to start-instances command

    xargs runs 'aws ec2 start-instances --instance-ids' for each ID, automating the start process.
  3. Final Answer:

    aws ec2 describe-instances --filters Name=instance-state-name,Values=stopped --query 'Reservations[].Instances[].InstanceId' --output text | xargs -n1 aws ec2 start-instances --instance-ids -> Option A
  4. Quick Check:

    Filter stopped instances and start each with xargs [OK]
Quick Trick: Use filters and xargs to automate instance starts [OK]
Common Mistakes:
  • Trying to start instances without IDs
  • Using invalid commands like 'list-stopped-instances'
  • Passing filters directly to start-instances

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes