Getting Started with AWS CLI
credits to Vimal Daga Sir

Getting Started with AWS CLI

Have you ever imagined if you had to run 100s of instances at a time to solve a particular use-case.

We all know much tedious(somewhat) is to select the required options always to launch a single instance in AWS. Noways everywhere we need automation. And in the present world DevOPs is playing vital role in the Automation world. Within seconds entire setup is done. This cant be achieved by WebUI. Hence we use command interface.Even major cloud services like AWS , Google CLoud etc have their own CLI. With the help of one single command we launch N number of instances.

In this article I will be going to perform some basic tasks using AWS CLI

I will use AWS CLI to create a Key-pair, Security group and an EBS volume (also attach it)and use these to launch an EC2 instance in the AWS cloud

Creating a Key Pair

Use the below command to create a Key Pair

aws ec2 create-key-pair --key-name MyKeyPair
This command generates a Key Pair which is a 2048-bit RSA key pair with the specified name. Amazon EC2 stores the public key
and displays the private key for
you to save to a file.
The private key is returned as an unencrypted PEM encoded
PKCS#1 private key.
No alt text provided for this image

We can confirm about the KeyPair by running the below command

aws ec2 describe-key-pairs
No alt text provided for this image

We can check it AWS Web console as well

No alt text provided for this image

Hurray!!! we have made a Key Pair using AWS CLI


Creating a Security Group and Configuring it

Creating a Security Group:

aws ec2 create-security-group --group-name my-sg --description "MySG"

This returns a id of Security Group in JSON format

No alt text provided for this image

Checking in the web console

Go to EC2 Dashboard --> Security Groups

No alt text provided for this image

We can that the Inbound Rules shows that there no permissions given which means no one from outside world are allowed

Configuring the Security Group

Lets add SSH rule using AWS CLI

For adding SSH rule

aws ec2 authorize-security-group-ingress --group-id sg-0ae53f599ea33dd12 --protocol tcp --port 22 --cidr 0.0.0.0/0

In the web console we can see that one permission is added in the inbound rules

No alt text provided for this image

Hurray!!! we have created and configured the Security Group

Launching an AWS Instance

Now we will launch an AWS instance using the generated key and security group.

aws ec2 run-instances --image-id ami-04b1ddd35fd71475a --instance-type t2.micro --key-name MyKeyPair --subnet-id subnet-85a3aded --count 1
 --security-group-ids sg-0ae53f599ea33dd12

This one command will launch an AWS instance using the key MyKeyPair and the given Security Group ID.

No alt text provided for this image

We check the info of the instance using the below command

aws ec2 describe-instances

This command will give the entire info about the instance(even if they are running or stopped)

No alt text provided for this image

Checking the AWS Web console

No alt text provided for this image

Now we will make an EBS volume of 1 GiB and attach it to the running instance using the AWS CLI

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

This command will create an EBS volume of 1GiB in the Availability Zone : ap-south-1a

No alt text provided for this image

NOTE: The Volume created and the instance should be in the same Availability Zone as we have to attach the volume to the instance.

Attaching the Volume created to the instance running

Now we will attach the created EBS volume to the running instance using the below command.

aws ec2 attach-volume --volume-id vol-0e79b46247a85efa4 --instance-id i-0b77dfa7af12c1a92 --device /dev/sdf

Here we need to specify the instance-id and volume-id

No alt text provided for this image

Hence we have attached the EBS volume to the running instance.

Hence we have created a Key-Pair, configured a Security Group and using it we have started an instance and attached a EBS volume to it.

Thanks to Vimal Daga Sir for giving this task

References:

  1. AWS documentation on key-pairs, creating volumes and run an instance.

Thanks for giving it a read.

Feel free to ask any queries

Author: Syed Faheemuddin

Email: [email protected]


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

Syed Faheemuddin的更多文章

  • AWS CLI TASK2

    AWS CLI TASK2

    In this article I will integrate various services of AWS : EC2, EBS, S3 and Cloud Front I will launch a webserver using…

  • Transfer Learning using MobileNet

    Transfer Learning using MobileNet

    What is Transfer Learning? Transfer learning is the reuse of a pre-trained model on a new problem. It's currently very…

  • Automation using pipeline in Jenkins Image integrating with Docker and GitHub

    Automation using pipeline in Jenkins Image integrating with Docker and GitHub

    In this task I will be developing a CI/CD pipeline which downloads the code form GitHub and deploys on respective…

  • Infrastructure development With Ansible and Docker

    Infrastructure development With Ansible and Docker

    Nowadays Automation is everywhere Ansible and Docker are the most important tools in DevOPs and they are playing a…

    6 条评论
  • Jenkins Testing and Production Environment with Automation

    Jenkins Testing and Production Environment with Automation

    TASK 1 --> MLOPS and DevOps Assembly Lines In this task I will explain a SMARTER and AGILE way to manage testing and…

  • Integrating ML with DevOps

    Integrating ML with DevOps

    In this article I will explain my first MLOPS project which successfully completed under Vimal Daga Sir. In this…

社区洞察

其他会员也浏览了