Working with AWS CLI

Rohit Kumar Dubey
3 min readOct 21, 2020

We’ll be learning how to launch an ec2 instance, creating key pairs, security groups, creating a simple EBS volume and attaching it to the launched ec2 instance.

Let’s get started…

STEP 1: Firstly we need to configure our AWS using the following command.

aws configure

Enter your credentials (access key and secret key), the region you want to work on and the default output format and then press enter.

STEP 2: Now we’ll move on for creating a new key pair through the following command:

aws ec2 create-key-pair --key-name <Key Name>
Key Pair creation

Save the content of the key pair in a file with an extention of .pem so that it could be used further.

Saving the key pair content through notepad as taskkey.pem

We can also cross check if our process was successful through AWS WebUI.

The key was created successfully

STEP 3: Creating a security group for attaching in the instance using the following command:

aws ec2 create-security-group --group-name <Security group name> --description <sg description>

The Security group gets created.

Secuirty group created

Cross checking through the WebUI.

Security group named tasksg has been successfully created

STEP 4: Now we’ll launch an instance wherein we’ll attach the key pair and the security group we just created using the following command:

aws ec2 run-instances --image-id <image id> --instance-type <instance type> --security-groups <security group name> --key-name <key name>

The ec2 instance gets launched after running this command.

ec2 instance created

Cross checking it through WebUI.

Instance successfully created

STEP 5: Creating an EBS volume of 1 GB using the following command:

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

The EBS volume of 1GB gets created.

EBS volume created

Cross checking through WebUI.

EBS volume successfully created

STEP 6: Attaching the EBS volume which was just created to the instance through the following command:

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

The EBS gets attached to the created instance.

EBS attached

Cross checking through WebUI.

EBS successfully attached

Summary:

  • Created a key pair.
  • Created a security group.
  • Launched an ec2 instance wherein the created key pair and security group were attached.
  • Created an EBS volume of 1 GB.
  • Attached the EBS volume to the instance.

--

--

Rohit Kumar Dubey

Cloud ☁️ & DevOps 🐳 Enthusiast | Learner 📚 | Explorer 👨🏻‍💻