aws ec2Find, start and stop EC2 instances from the CLI
aws ec2 manages virtual machines, their disks, networks and security groups. Day to day you use describe-instances with --filters and --query to find instances, and start/stop/reboot to operate them. Learning --query (JMESPath) and --output turns its huge JSON into exactly the table or list you need.
aws ec2 describe-instances|start-instances|stop-instances|... [--instance-ids ID...] [--filters Name=,Values=] [--query EXPR] [--output json|text|table]You need a quick inventory of the instances in this region: who is running, what type, which private IP.
aws ec2The EC2 service: instances, AMIs, EBS volumes, security groups, VPC networking.
Every aws ec2 command is one call to the regional EC2 Query API (ec2.us-east-1.amazonaws.com), signed with SigV4 and authorised against IAM actions like ec2:DescribeInstances or ec2:StopInstances. describe-instances returns reservations (one per launch request), each with a list of instances, and the CLI follows NextToken pagination automatically. --filters is applied by EC2 on the server, so less data comes back; --query is applied by the CLI afterwards with JMESPath, so it can reshape anything. stop-instances asks EC2 to shut the guest OS down via ACPI and returns immediately with the state change (running to stopping); aws ec2 wait polls until the target state is reached. A stopped instance keeps its EBS volumes and private IP, loses its public IP and instance-store data, and stops billing for compute but not for storage.
describe-instancesList instances (all, or --instance-ids)--filters Name=X,Values=a,bServer-side filter: tag:Name, instance-state-name, vpc-id...--query EXPRJMESPath: pick fields, rename them with {Name:...}, filter with [?...]--output table|text|json|yamlFormatting for humans (table) or scripts (text, json)start/stop-instancesChange instance state (also reboot-instances); stop --force for a stuck stopterminate-instancesDelete the instance (and root volume if DeleteOnTermination)wait STATEBlock until instance-running, instance-stopped... (polls every 15 s)--dry-runCheck permissions without doing anything--region REGIONOverride the default region for this commanddescribe-volumesSame patterns for disks; describe-security-groups for firewallsParsing describe-instances JSON with grep and cutThe output is deeply nested and multi-line; field order and indentation aren't stable.
--query to select fields, --output text for shell loops, or jq on --output jsonUsing --query to filter thousands of instances: --query 'Reservations[].Instances[?State.Name==`running`]'It downloads every instance first and filters on your machine; slow and throttle-prone in large accounts.
--filters Name=instance-state-name,Values=running (server side), then --query to shapeterminate-instances when you meant stop-instancesTermination is permanent: the root volume is deleted by default and the instance can't come back.
Use stop for maintenance; enable termination protection (DisableApiTermination) on important instancesExpecting the same public IP after a stop/startAuto-assigned public IPv4 addresses are released on stop.
Use an Elastic IP, or better, a load balancer or DNS name in frontTry these on a Linux machine of your own. Each task has a hint and a solution.
The sandbox has ~/data/servers.txt (name, IP, state). Without network, practise the same 'filter then project' idea: print the names of the running servers only.
Turn ~/data/servers.txt into JSON with jq and select the stopped ones, the way --query would with [?State==`stopped`].
List the IDs of running instances tagged env=prod as plain text.
Find the stopped instance, start it, and block until it's running.
aws ec2Find, start and stop EC2 instances from the CLI
aws ec2 manages virtual machines, their disks, networks and security groups. Day to day you use describe-instances with --filters and --query to find instances, and start/stop/reboot to operate them. Learning --query (JMESPath) and --output turns its huge JSON into exactly the table or list you need.
aws ec2 describe-instances|start-instances|stop-instances|... [--instance-ids ID...] [--filters Name=,Values=] [--query EXPR] [--output json|text|table]You need a quick inventory of the instances in this region: who is running, what type, which private IP.
aws ec2The EC2 service: instances, AMIs, EBS volumes, security groups, VPC networking.
Every aws ec2 command is one call to the regional EC2 Query API (ec2.us-east-1.amazonaws.com), signed with SigV4 and authorised against IAM actions like ec2:DescribeInstances or ec2:StopInstances. describe-instances returns reservations (one per launch request), each with a list of instances, and the CLI follows NextToken pagination automatically. --filters is applied by EC2 on the server, so less data comes back; --query is applied by the CLI afterwards with JMESPath, so it can reshape anything. stop-instances asks EC2 to shut the guest OS down via ACPI and returns immediately with the state change (running to stopping); aws ec2 wait polls until the target state is reached. A stopped instance keeps its EBS volumes and private IP, loses its public IP and instance-store data, and stops billing for compute but not for storage.
describe-instancesList instances (all, or --instance-ids)--filters Name=X,Values=a,bServer-side filter: tag:Name, instance-state-name, vpc-id...--query EXPRJMESPath: pick fields, rename them with {Name:...}, filter with [?...]--output table|text|json|yamlFormatting for humans (table) or scripts (text, json)start/stop-instancesChange instance state (also reboot-instances); stop --force for a stuck stopterminate-instancesDelete the instance (and root volume if DeleteOnTermination)wait STATEBlock until instance-running, instance-stopped... (polls every 15 s)--dry-runCheck permissions without doing anything--region REGIONOverride the default region for this commanddescribe-volumesSame patterns for disks; describe-security-groups for firewallsParsing describe-instances JSON with grep and cutThe output is deeply nested and multi-line; field order and indentation aren't stable.
--query to select fields, --output text for shell loops, or jq on --output jsonUsing --query to filter thousands of instances: --query 'Reservations[].Instances[?State.Name==`running`]'It downloads every instance first and filters on your machine; slow and throttle-prone in large accounts.
--filters Name=instance-state-name,Values=running (server side), then --query to shapeterminate-instances when you meant stop-instancesTermination is permanent: the root volume is deleted by default and the instance can't come back.
Use stop for maintenance; enable termination protection (DisableApiTermination) on important instancesExpecting the same public IP after a stop/startAuto-assigned public IPv4 addresses are released on stop.
Use an Elastic IP, or better, a load balancer or DNS name in frontTry these on a Linux machine of your own. Each task has a hint and a solution.
The sandbox has ~/data/servers.txt (name, IP, state). Without network, practise the same 'filter then project' idea: print the names of the running servers only.
Turn ~/data/servers.txt into JSON with jq and select the stopped ones, the way --query would with [?State==`stopped`].
List the IDs of running instances tagged env=prod as plain text.
Find the stopped instance, start it, and block until it's running.