Bird
Raised Fist0
AWScloud~5 mins

Instance states (running, stopped, terminated) in AWS - Commands & Configuration

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
Introduction
When you use cloud servers called instances, they can be in different states like running, stopped, or terminated. Knowing these states helps you control your servers and costs.
When you want to start a server to run your website or app.
When you want to pause a server without deleting it to save money.
When you want to permanently delete a server you no longer need.
When you want to check if your server is ready to accept connections.
When you want to restart a server after fixing a problem.
Commands
This command lists all your instances that are currently running so you know which servers are active.
Terminal
aws ec2 describe-instances --filters Name=instance-state-name,Values=running
Expected OutputExpected
{ "Reservations": [ { "Instances": [ { "InstanceId": "i-0abcd1234efgh5678", "State": { "Name": "running" }, "InstanceType": "t2.micro" } ] } ] }
--filters - Filters instances by their state.
This command stops the instance with the given ID, pausing it so you don't pay for running time but keep the data.
Terminal
aws ec2 stop-instances --instance-ids i-0abcd1234efgh5678
Expected OutputExpected
{ "StoppingInstances": [ { "InstanceId": "i-0abcd1234efgh5678", "CurrentState": { "Name": "stopping" }, "PreviousState": { "Name": "running" } } ] }
--instance-ids - Specifies which instance to stop.
This command lists all instances that are stopped, so you can confirm your server is paused.
Terminal
aws ec2 describe-instances --filters Name=instance-state-name,Values=stopped
Expected OutputExpected
{ "Reservations": [ { "Instances": [ { "InstanceId": "i-0abcd1234efgh5678", "State": { "Name": "stopped" }, "InstanceType": "t2.micro" } ] } ] }
--filters - Filters instances by their state.
This command permanently deletes the instance, freeing all resources and data associated with it.
Terminal
aws ec2 terminate-instances --instance-ids i-0abcd1234efgh5678
Expected OutputExpected
{ "TerminatingInstances": [ { "InstanceId": "i-0abcd1234efgh5678", "CurrentState": { "Name": "shutting-down" }, "PreviousState": { "Name": "stopped" } } ] }
--instance-ids - Specifies which instance to terminate.
This command lists all instances that have been terminated, confirming they are deleted and no longer available.
Terminal
aws ec2 describe-instances --filters Name=instance-state-name,Values=terminated
Expected OutputExpected
{ "Reservations": [] }
--filters - Filters instances by their state.
Key Concept

If you remember nothing else from this pattern, remember: running means active, stopped means paused but saved, and terminated means deleted forever.

Common Mistakes
Trying to start a terminated instance.
Terminated instances are deleted and cannot be started again.
Launch a new instance instead of trying to start a terminated one.
Stopping an instance but expecting it to keep running.
Stopping an instance pauses it and stops all running processes.
Use start-instances command to resume a stopped instance.
Terminating an instance by mistake without backup.
Termination deletes all data and cannot be undone.
Always create snapshots or backups before terminating.
Summary
Use describe-instances with filters to check instance states like running, stopped, or terminated.
Use stop-instances to pause a running instance without deleting it.
Use terminate-instances to permanently delete an instance and free resources.

Practice

(1/5)
1. Which AWS EC2 instance state means the instance is currently powered on and ready to use?
easy
A. Running
B. Stopped
C. Terminated
D. Pending

Solution

  1. Step 1: Understand EC2 instance states

    Instances can be in states like running, stopped, or terminated, indicating their power and availability status.
  2. Step 2: Identify the state meaning 'powered on'

    The 'running' state means the instance is powered on and ready to use.
  3. Final Answer:

    Running -> Option A
  4. Quick Check:

    Running = Powered On [OK]
Hint: Running means instance is on and usable [OK]
Common Mistakes:
  • Confusing stopped with running
  • Thinking terminated means running
  • Mixing pending with running
2. Which AWS CLI command correctly stops a running EC2 instance with ID i-1234567890abcdef0?
easy
A. aws ec2 terminate-instances --instance-ids i-1234567890abcdef0
B. aws ec2 reboot-instances --instance-ids i-1234567890abcdef0
C. aws ec2 start-instances --instance-ids i-1234567890abcdef0
D. aws ec2 stop-instances --instance-ids i-1234567890abcdef0

Solution

  1. Step 1: Identify command to stop instance

    The command to stop an instance is stop-instances.
  2. Step 2: Match instance ID usage

    The command must include --instance-ids i-1234567890abcdef0 to specify the instance.
  3. Final Answer:

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

    Stop instance = stop-instances command [OK]
Hint: Stop instance uses 'stop-instances' command [OK]
Common Mistakes:
  • Using terminate instead of stop
  • Using start instead of stop
  • Using reboot instead of stop
3. What will be the state of an EC2 instance immediately after running this AWS CLI command?
aws ec2 terminate-instances --instance-ids i-0abcdef1234567890
medium
A. Running
B. Stopped
C. Terminated
D. Pending

Solution

  1. Step 1: Understand the terminate-instances command

    This command deletes the instance permanently, changing its state to terminated.
  2. Step 2: Identify the resulting state

    After termination, the instance cannot be started again and is marked as terminated.
  3. Final Answer:

    Terminated -> Option C
  4. Quick Check:

    Terminate command = Terminated state [OK]
Hint: Terminate means instance is deleted permanently [OK]
Common Mistakes:
  • Thinking terminated means stopped
  • Confusing terminate with stop
  • Expecting instance to restart automatically
4. You tried to start an EC2 instance but got an error saying the instance does not exist. What is the most likely cause?
medium
A. The instance is terminated
B. The instance is in running state
C. The instance is in stopped state
D. The instance is pending

Solution

  1. Step 1: Analyze error meaning

    If AWS says the instance does not exist, it usually means it was deleted or terminated.
  2. Step 2: Match instance state to error

    Terminated instances are removed and cannot be started again, causing this error.
  3. Final Answer:

    The instance is terminated -> Option A
  4. Quick Check:

    Instance not found = Terminated state [OK]
Hint: Instance not found means terminated, not stopped [OK]
Common Mistakes:
  • Assuming stopped means instance missing
  • Confusing running with missing
  • Ignoring termination possibility
5. You want to save costs by stopping an EC2 instance but keep its data intact for later use. Which instance state should you use and why?
hard
A. Terminate, because it deletes the instance and saves all costs
B. Stop, because it powers off the instance but keeps data on the disk
C. Running, because it keeps the instance active and data safe
D. Pending, because it prepares the instance for shutdown

Solution

  1. Step 1: Understand cost and data retention

    Stopping an instance powers it off but keeps the attached storage intact, preserving data.
  2. Step 2: Compare with termination

    Terminating deletes the instance and storage, losing data and cannot be restarted.
  3. Step 3: Choose correct state for saving costs and keeping data

    Stopping is the correct choice to save costs while keeping data safe.
  4. Final Answer:

    Stop, because it powers off the instance but keeps data on the disk -> Option B
  5. Quick Check:

    Stop = Save cost + keep data [OK]
Hint: Stop to save cost and keep data intact [OK]
Common Mistakes:
  • Choosing terminate and losing data
  • Thinking running saves cost
  • Confusing pending with stop