Amazon Web Services (AWS) - Start an EC2 instance using the AWS CLI

by
Jeremy Canfield |
Updated: April 19 2023
| Amazon Web Services (AWS) articles
This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.
The aws ec2 describe-instances command can be used to list your EC2 instances.
aws ec2 describe-instances
--filter can be used to only return the JSON for an specific instance.
aws ec2 describe-instances --filters "Name=tag:Name,Values=my-instance"
Something like this should be returned (this is just a small subset of the output that would be returned). Notice in this example that the EC2 ID is i-09112345cf1abcdd2 and the state of the instance is stopped.
{
"Reservations": [
{
"Instances": [
{
"AmiLaunchIndex": 0,
"ImageId": "ami-09d123474b6cabcda",
"InstanceId": "i-09112345cf1abcdd2",
"InstanceType": "t2.micro",
"KeyName": "aws",
"LaunchTime": "2022-11-06T09:23:52+00:00",
"State": {
"Code": 80,
"Name": "stopped"
},
"Tags": [
{
"Key": "Name",
"Value": "my-instance"
}
]
}
]
}
]
}
The aws ec2 start-instances command can be used to start the instance.
~]$ aws ec2 start-instances --instance-id i-09112345cf1abcdd2
{
"StartingInstances": [
{
"CurrentState": {
"Code": 0,
"Name": "pending"
},
"InstanceId": "i-09112345cf1abcdd2",
"PreviousState": {
"Code": 80,
"Name": "stopped"
}
}
]
}
Did you find this article helpful?
If so, consider buying me a coffee over at