Launching EC2 Instance and attaching EBS volume to it using CLI

Launching EC2 Instance and attaching EBS volume to it using CLI


No alt text provided for this image

Hello everyone!!???♀????♀?

??After Reading This Article You will come to know about Basics Of AWS CLI and how to manage AWS Console using AWS CLI.

So let’s begin…..??

??What Is 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.

To Learn More about AWS CLI: https://aws.amazon.com/cli/

??Installing AWS CLI :

The Installation of AWS CLI is very simple. You just have to download the application compatible with your Operating System from the link provided below and just install it as you install any-other software in your system.

Link: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-windows.html

Once you have installed AWS CLI in your system open your Terminal or Command Prompt. You can check it whether its working or not:
No alt text provided for this image

??Pre-requisites :

AWS-cli setup

?Create an account on AWS.

?Go to Identity & Access Management (IAM), create a user and generate an access key to configure AWS on your machine. You need to give Power Access Permissions to this IAM user.

?Open the command line and configure AWS

aws configure

? Provide access key and secret you just generated, along with that provide the region you are going to deploy your cluster in. AWS recommends users to choose regions geographically close to them to reduce latency and costs.

??? After this , now what we are going to do is to :

?? Create a key pair

??Create a security group

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

??Create an EBS volume of 1 GB.

?? The final step is to attach the above created EBS volume to the instance you created in the previous steps.

?? The main motive is to launching an ec2 instance

?? Now, firstly we have to create our own key pair for that we take help of AWS so here to take help we write :

 ?????Create a key pair

A key pair, consisting of a private key and a public key, is a set of security credentials that you use to prove your identity when connecting to an instance. Amazon EC2 stores the public key, and you store the private key.

  • To create a key pair we need to run the below mentioned command.
?? aws ec2 create-key-pair --key-name Key Name

No alt text provided for this image

?? Now, we have to create new security group by command .

?????Create a Security Group

  • To Create a Security Group We can run below mentioned Command.
aws ec2 create-security-group --group-name Name --description "DESCRIPTION"

No alt text provided for this image

 ?? By using this newly created key pair & security group we have to launch new instance.

?????Launch an ec2 instance

  • You can launch any OS which u want and each OS has a unique id.

To launch an instance, we need the following command:

??aws ec2 run-instances --image-id "ImageID" --key-name "KeyName" --instance-type "Type of Instance" --count "No.ofInstances" --security-group-ids "SecurityGroupID"
  • In this, I am going to provision my Amazon AMI. For that we have a command:

?? Command is :

?? aws run-instances — image-id ami-0e306788ff2473ccb — instance-type t2.micro — subnet-id subnet-37666f5f — count 1 — security-group-ids sg-082e7e59275801fcd — key-name TaskKeyPair
No alt text provided for this image
New instance is launched…… ????

???? You can see instance is launched in CLI OR GUI…??

??Now, we have to create an EBS volume of 1 GB.

?????Create an EBS volume of 1 GB

Amazon Elastic Block Store provides raw block-level storage that can be attached to Amazon EC2 instances.

?? Command is :

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

No alt text provided for this image

?????Attach the above created EBS volume to the instance that we created in the previous steps

?? Now, we can attach the volume by following command :

?? aws ec2 attach-volume — volume-id vol-0522f336c28172eb1 — instance-id i-07345102940d94e27 — device /dev/sdf

??Device name can be sdf or svdh

No alt text provided for this image

???? We attached our EBS volume of 1GB with an ec2 -instance. So now ,our task is accomplished ??

I hope it's helpful for you all after reading this.
"Thank you"


要查看或添加评论,请登录

Shruti Sharma的更多文章

社区洞察

其他会员也浏览了