Generate a key pair to securely access the EC2 instance via SSH, and save the private key to your local computer
aws ec2 create-key-pair --key-name LinuxEC2KP --query 'KeyMaterial' --output text > LinuxEC2KP.pem
chmod 400 LinuxEC2KP.pem
aws ec2 create-security-group --group-name Allow-http_SSH-SG --description " Allow HTTP and SSH connection to EC2 instance"
aws ec2 describe-security-groups --filters "Name=group-name,Values=Allow-http_SSH-SG"
aws ec2 authorize-security-group-ingress --group-id “replace me with the group-id” --protocol tcp --port 22 --cidr 0.0.0.0/0 aws ec2 authorize-security-group-ingress --group-id “replace me with the group-id” --protocol tcp --port 80 --cidr 0.0.0.0/0
aws ec2 describe-images
--region us-east-1
--owners amazon
--filters "Name=name,Values=amzn2-ami-hvm--x86_64-gp2"
--query "Images[].{ID:ImageId,Name:Name}"
--output table
aws ec2 run-instances --image-id "replace me with the image-id" --count 1 --instance-type t2.micro --key-name Allow-http_SSH-SG --security-group-ids “replace me with the group-id”