Skip to main content

Command Palette

Search for a command to run...

Creating an EC2 instance on AWS using AWSCLI

Published
1 min read
M

I am a DevOps Engineer at Fidelity National Information Services and responsible to automate the manual things and create CI/CD pipelines in software development lifecycle.

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.

D

It is a very nice article to understand.and it is very helpful to us.

1