* Launching a complete Instance and Mount a EBS volume by CLI in AWS *

Kewal Shah
4 min readOct 26, 2020

Task:

πŸ”… 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.

** So lets understand basic definitions, which we are gonna use in the task**

1> Key-pair :

Amazon AWS uses keys to encrypt and decrypt login information. At the basic level, a sender uses a public key to encrypt data, which its receiver then decrypts using another private key. These two keys, public and private, are known as a key pair.

2> Security group :

AWS Security Groups are a flexible tool to help you secure your Amazon EC2 instances. AWS Security Groups are just one of several tools AWS offers to help you secure your cloud environment, but that doesn’t mean AWS security is hands-off.

3> EBS Storage :

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.

Prerequisites of the task:

1.) You need to sure that you already install the AWS CLI software/program in your system/workplace. AWS CLI provides us the interference between the AWS and the CLI means terminal.

If not then install the software by the below link. πŸ‘‡πŸ‘‡

https://awscli.amazonaws.com/AWSCLIV2.msi

Now, you can check whether AWS CLI install or not then run the below command πŸ‘‡πŸ‘‡

aws

2.) After installing the AWS CLI successfully then first you required to make a IAM (Identity and Access Management) means a user who are going to access the AWS.

β†ͺ For this you need to enter the AWS account with the root account.

β†ͺ Go to the IAM service.

β†ͺ Create user by clicking on the Add User

β†ͺ Create user by clicking on the Add User

β†ͺ Give the user name and tick the programmatic access and Amazon management console which make the access key ID and the secret access key for login through the AWS CLI and GUI.

3.) After this you run the command in your cmdπŸ‘‡πŸ‘‡

aws configure

To configure the access key and secrete key to login into the AWS. give the access key and secret key which we download previously.

So lets get started the task:

Step 1 :- How to create key pair with the help of CLI and GUI:

Step 2 :- Create a security group.

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

Step 3 :- Launch an instance using the above created key pair and security group:

For this you need the image-id, instance-type, subnet-id, security group id and the key pair name. You can got it by the AWS console.

aws ec2 run-instances --image-id <value> --instance-type <value> --count <value> --subnet-id <value> --security-group-ids <value>      --key-name <name>

Step 4 :- Create an EBS volume of 1 GB.

aws ec2 create-volume --availability-zone <value> --size <value>

Step 5 :- The final step is to attach the above created EBS volume to the instance you created in the previous steps. For this you need volume id which is created in the step 4, instance id which is created in the step 3 and device name.

aws ec2 attach-volume --volume-id <value> --instance-id <value> --device /dev/sdf

Finally you have attached EBS volume to your instance.

--

--