if you haven't installed the AWS CLI on your computer, you can download and install it from the AWS official website.
Configure your credentials by running this command on your terminal - 'aws configure'
Use this command line to create a keypair
<aws ec2 create-key-pair --key-name YOURKEYPAIRNAME>
Use this line of command to create a Security Group
<aws ec2 create-security-group --group-name "security-group-name" --description "description">, note the "GroupId" given then run this command line
<aws ec2 authorize-security-group-ingress --group-id "GroupId" --protocol tcp --port 22 --cidr 0.0.0.0/0>
Use this command line to run your EC2
<aws ec2 run-instances --image-id "ami-id" --instance-type t2.micro --key-name "Keypair-name" --security-group-ids "SecurityGroupId">
To verify whether the EC2 instance created using the AWS CLI is created as per need, log in to your AWS Console and open the EC2 service and check for the instance.