0
0
AWScloud~5 mins

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

Choose your learning style9 modes available
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.