AWS cli | Launching Instance and Attaching EBS volume |

AWS cli:-

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.

AWS EC2 Instances:-

Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides secure, resizable compute capacity in the cloud. It is designed to make web-scale cloud computing easier for developers. Amazon EC2’s simple web service interface allows you to obtain and configure capacity with minimal friction. It provides you with complete control of your computing resources and lets you run on Amazon’s proven computing environment.

EBS Volume:-

Amazon Elastic Block Store (EBS) is an easy to use, high performance block storage service designed for use with Amazon Elastic Compute Cloud (EC2) for both throughput and transaction intensive workloads at any scale. A broad range of workloads, such as relational and non-relational databases, enterprise applications, containerized applications, big data analytics engines, file systems, and media workflows are widely deployed on Amazon EBS.

Task Description:-

▹ Create a Security Group and add rules for ssh and http to the same security group.

▹ Launch an EC2 instance using the the above create key-pair and security group.

▹Create an EBS volume of 1GB.

▹ Attach the above create EBS volume to the above launched instance.

Lets See the solution of the above Task:-

For configuring the AWS cli we have to download the aws cli sdk from the aws site and just install it and after that configure the aws cli by providing the access key and secret key to the command prompt. for configuring use

aws configure

For checking use the following cmd:

aws --version

Step 2: Create a key-pair:-

While launching a instance key pair work like a password to that instance. For creating the key pair use the following cmd:

aws ec2 create-key-pair --key-name task3 --query KeyMaterial --output text > task3.pem

The above cmd will create key pair having name task3.

Also the above cmd will upload the keyMaterial to a file name task3.pem which can be use to connect to the instance using the ssh/putty .

Step 3: Create a security group:-

For creating a security group we can use the following cli amd:

aws ec2 create-security-group --group-name task3 --description "My security group"  --vpc-id vpc-aef7eac6

In the above cmd we have specify the security group name and the vpc id .It will create a security group but not assign any rules to the following security group.

Step 4: Assign the rules for the ssh and http protocol to the above created security group:-

aws ec2 authorize-security-group-ingress --group-name task3          --ip-permissions IpProtocol=tcp, FromPort=22 ,ToPort=22,     IpRanges=[{CidrIp=}] IpProtocol=tcp, FromPort=80,ToPort=80, IpRanges=[{CidrIp=}]

In the above code we have provided the security group name and also provided the info related to the two protocols i.e ssh(port=22) and http(port=80).

Step 5: Launch an EC2 instance using the the above create key-pair and security group:-

While launching the EC2 instance we have to provide a key-pair and a security group which we have created above.

aws ec2 run-instances  --image-id ami-0e306788ff2473ccb 
--instance-type t2.micro --security-group-ids sg-0b41e87e931f02571 --subnet-id subnet-78003a10 --count 1 --key-name task3

The above cmd will launch a EC2 instance having the above created keypair and security group.

Step 6: Create an EBS volume of 1GB:-

aws ec2 create-volume --availability-zone ap-south-1a  --size 1 --volume-type gp2

The above cmd will create a ebs volume in the availability zone ap south 1a we have create the volume in the same zone in which we have launch out instance.

Step 7: Attach the above create EBS volume to the above launched instance.:-

aws ec2 attach-volume --device  /dev/sdf  --instance-id i-08865d2867a7be969  --volume-id vol-02b018cb43f44652a

For attaching the ebs volume it is necessary to give the device name and the id of instance to which we want to attach and the id of the volume which is to be attached.

The Final outcome will be that by using the security group we can access the instance and we can see that the ebs volume having name /dev/xvdf has been attach to the same instance successfully.

Thanks For Reading….

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store