aws cli : ec2

Q. How to create an ec2 instance?
AMI_ID="ami-0ded8326293d3201b"
INSTANCE_TYPE="t2.micro"
SECURITY_GROUP="sg-0a49f18307385e4ab"
REGION="ap-south-1"
aws ec2 run-instances --image-id $AMI_ID --instance-type $INSTANCE_TYPE --region $REGION

Other basic parameter:
--key-name $KEY_PAIR
--subnet-id $SUBNET_GROUP
--count $COUNT

Q. How to stop an ec2 instance?
INSTANCE_IDS="i-00fbb44a881c3cd72 i-08bb67d930a3a620f"
REGION="ap-south-1"
aws ec2 stop-instances --instance-ids $INSTANCE_IDS --region $REGION

Q. How to start an ec2 instance?
INSTANCE_IDS="i-00fbb44a881c3cd72 i-08bb67d930a3a620f"
REGION="ap-south-1"
aws ec2 start-instances --instance-ids $INSTANCE_IDS --region $REGION

Q. How to get instance id of an ec2 from an IP address?
PRIVATE_IP_ADDRESS="172.31.10.251"
aws ec2 describe-instances --filter Name=private-ip-address,Values=$PRIVATE_IP_ADDRESS --query 'Reservations[].Instances[].InstanceId' --output text

Q. How to get volume ids of volumes attached to an ec2 instance?
INSTANCE_ID="i-08bb67d930a3a620f"
aws ec2 describe-volumes --filters Name=attachment.instance-id,Values=$INSTANCE_ID --query 'Volumes[].VolumeId' --output text

Q. How to get size of volumes attached to an ec2 instance?
INSTANCE_ID="i-08bb67d930a3a620f"
aws ec2 describe-volumes --filters Name=attachment.instance-id,Values=$INSTANCE_ID --query 'Volumes[].Size' --output text

Q. How to get volume ids and size of volumes attached to an ec2 instance?
INSTANCE_ID="i-08bb67d930a3a620f"
aws ec2 describe-volumes --filters Name=attachment.instance-id,Values=$INSTANCE_ID --query 'Volumes[].[VolumeId,Size]' --output text

Q. How to stop an ec2 instance in hibernate mode?
INSTANCE_IDS="i-00fbb44a881c3cd72 i-08bb67d930a3a620f"
REGION="ap-south-1"
aws ec2 stop-instances --instance-ids $INSTANCE_IDS --region $REGION --hibernate
Note: You can't enable or disable hibernation for an instance after you launch it. You must configure it at launch time.

Q. How to terminate ec2 instances?
INSTANCE_IDS="i-00fbb44a881c3cd72 i-08bb67d930a3a620f"
REGION="ap-south-1"
aws ec2 terminate-instances --instance-ids $INSTANCE_IDS --region $REGION