AWS CLI for EC2
AWS CLI for EC2
Examples
Example 1: List All instances from Default Region
1
aws ec2 describe-instances
Example 2: List All instances with query
- With all informations
1
2
3
aws ec2 describe-instances \
--region "us-east-1" \
--query "Reservations[].Instances[]"
- With IAM, Security Group
1
2
3
4
aws ec2 describe-instances \
--region "us-east-1" \
--query "Reservations[].Instances[].{InstanceId:InstanceId,Name:Tags[?Key=='Name']|[0].Value,InstanceType:InstanceType,PrivateIp:PrivateIpAddress,PublicIP:PublicIpAddress,SubnetId:SubnetId,VpcId:VpcId,Groups:join(',',NetworkInterfaces[].Groups[].GroupId),IamInstanceProfile:IamInstanceProfile.Arn}" \
--output table
Example 3: Start, Stop instance
1
aws ec2 stop-instances --instance-ids <instance id>
1
aws ec2 stop-instances --instance-ids <instance id>
References
This post is licensed under CC BY 4.0 by the author.