Building Basic AWS Cloud Infrastructure Using AWS CLI Interface!!

What is AWS CLI ❔

Priyanka Gavali
4 min readOct 13, 2020

The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.

⚡ To use AWS Cloud through CLI only Prerequisite is to Install AWS CLI SDK tool .

🔰 TASK DESCRIPTION

🔺 Create a key pair

🔺 Create a security group

🔺 Launch an instance using the above created key pair and security group

🔺 Create an EBS volumeof 1 GB and attach to the instance we created above

All the above steps must be performed using AWS CLI

💢TASK COMPLETION :

Step 1:To complete this task 1st we need to log in to aws CLI Interface with Access and Secret key and for this we need to create IAM user with Administrator Access.

Step 2:Command used to Log In into AWS CLI is ,

aws configure

Step 3: Now we successfully Logged In to AWS Account . After these We have to create Private Key to connect to the ec2 Instance . For creating Key Pair we have command as :

aws create-key-pair --key-name key_name

To Download the Key Pair .pem File We have to Use following command which pipe the key pair into the file

aws create-key-pair --key-name <keyname> --query "keyMaterial" --output text > <keyname>

We can also Generate Key of Our Own choice using ssh keygen for avoiding ssh login errors using command :

ssh-keygen -t rsa -C "keyname" -f ~/.ssh/my-key

And import this key using :

aws ec2 import-key-pair --key-name "my-key" --public-key-material fileb://~/.ssh/my-key.pub

Step 4:For Creating Security Group Command is :

aws ec2 create-security-group --group-name <name> --description <"description">

To Set Inbound or Ingress Rule to authorize the outside traffic we have the command as :

aws ec2 authorize-security-group-ingress --group-id security_group_id --protocol    protocol_name --port port_no --cidr cidr_block_value

Step 5:Now we have to Launch one EC2 Instance using above Key pair and Security Group .To launch ec2 instance AWS CLI has command as :

aws ec2 run-instances   --security-group-ids   group_id   --instance-type _type_ --image-id ami_id   --key-name key_name  --count no_of_instance

Step 6: After Launching EC2 Instance now we have to create one EBS Volume of 1 GB and attach it to the EC2 Instance we launched .

To Create EBS Volume AWS CLI has command as :

aws ec2 create-volume --volume-type volume_type --size volume_size --availability-zone AZ_name

To Attach EBS Volume to EC2 Instance we have command :

aws ec2  attach-volume   --volume-id volume_id   --instance-id instance_id  --device device_name

Step 7:We can also check the EBS Volume is attached to our EC2 Instance by Connecting to EC2 Instance via SSH . By using fdisk -l we can see the partitions of Hard Disks we attach to our EC2 Instance .

Step 8:At last we have to detach the volume and terminate the ec2 instance ,Easily we can do this using following Commands:

For Detaching the volume

aws ec2  detach-volume  --volume-id  volume_id

For Terminating the Ec2 Instance

aws ec2 terminate-instances --instance-ids  instance_id

And 3d TASK OF ARTH, AWS CSA & Developer Training is Completed Successfully🎉🎉

THANK YOU FOR READING The ARTICLE…❕❕

--

--