Install AWSCLI
sudo apt update
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
Note: if unzip command not installed
sudo apt install unzip
Create Key pair
aws ec2 create-key-pair --key-name MyKeyPair
Create Security Group to attach to ec2 instance
aws ec2 create-security-group --group-name=my-sg --description="My security group"
Note: Copy group-id
Add inbound rule to security-group
aws ec2 authorize-security-group-ingress --group-id=sg-0732102fbf4ea2fe3 --protocol=tcp --port=443 --cidr=0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-id=sg-0732102fbf4ea2fe3 --protocol=tcp --port=22 --cidr=0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-id=sg-0732102fbf4ea2fe3 --protocol=tcp --port=80 --cidr=0.0.0.0/0
Create instance
aws ec2 run-instances --image-id=ami-0fc5d935ebf8bc3bc --instance-type=t2.micro --region=us-east-1 --key-name=MyKeyPair --security-groups=my-sg
Check your ec2 dashboard and try to access your instance.
Congratulations ๐
You have created an ec2 instance using AWSCLI.
Do follow me on Linkedin: Linkedin-MadhupPandey for more such an interesting AWS services.
ย