AWS EC2 Commands

EC2 instance management

List Instances

aws ec2 describe-instances # list all instances
aws ec2 describe-instances --instance-ids i-xxx # describe specific instance
aws ec2 describe-instances --filters Name=tag:Name,Values=MyServer # filter by tag

Start and Stop

aws ec2 start-instances --instance-ids i-xxx # start instance
aws ec2 stop-instances --instance-ids i-xxx # stop instance
aws ec2 reboot-instances --instance-ids i-xxx # reboot instance
aws ec2 terminate-instances --instance-ids i-xxx # terminate instance

Create Instance

aws ec2 run-instances --image-id ami-xxx --instance-type t2.micro # launch instance
aws ec2 run-instances --image-id ami-xxx --count 2 --instance-type t2.micro # launch multiple

Key Pairs

aws ec2 describe-key-pairs # list key pairs
aws ec2 create-key-pair --key-name MyKey # create key pair
aws ec2 delete-key-pair --key-name MyKey # delete key pair

Security Groups

aws ec2 describe-security-groups # list security groups
aws ec2 create-security-group --group-name MyGroup --description Desc # create
aws ec2 authorize-security-group-ingress --group-id sg-xxx --protocol tcp --port 22 --cidr 0.0.0.0/0 # add rule