Bird
0
0

You want to automate creating an EC2 instance and tagging it in one script. Which AWS CLI command sequence correctly achieves this?

hard📝 Best Practice Q15 of 15
AWS - CLI
You want to automate creating an EC2 instance and tagging it in one script. Which AWS CLI command sequence correctly achieves this?
Aaws ec2 create-tags --resources <instance-id> --tags Key=Name,Value=MyInstance && aws ec2 run-instances --image-id ami-12345 --count 1 --instance-type t2.micro
Baws ec2 run-instances --image-id ami-12345 --count 1 --instance-type t2.micro && aws ec2 create-tags --resources <instance-id> --tags Key=Name,Value=MyInstance
Caws ec2 run-instances --image-id ami-12345 --count 1 --instance-type t2.micro --tags Key=Name,Value=MyInstance
Daws ec2 run-instances --image-id ami-12345 --count 1 --instance-type t2.micro --tag Name=MyInstance
Step-by-Step Solution
Solution:
  1. Step 1: Understand EC2 instance creation and tagging

    Creating an instance and tagging it are separate steps; tags are added after instance creation.
  2. Step 2: Analyze command sequences

    aws ec2 run-instances --image-id ami-12345 --count 1 --instance-type t2.micro && aws ec2 create-tags --resources --tags Key=Name,Value=MyInstance runs instance creation first, then tags it using the instance ID placeholder, which is correct.
  3. Step 3: Identify incorrect options

    The sequence that tags before the instance exists will fail; sequences attempting to add tags directly in run-instances use invalid syntax.
  4. Final Answer:

    aws ec2 run-instances --image-id ami-12345 --count 1 --instance-type t2.micro && aws ec2 create-tags --resources --tags Key=Name,Value=MyInstance -> Option B
  5. Quick Check:

    Create then tag = B [OK]
Quick Trick: Create instance first, then tag it separately [OK]
Common Mistakes:
  • Trying to tag before instance exists
  • Using wrong tag syntax in run-instances
  • Combining commands incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes