Using AWS CLI to launch an EC2 Instance - TASK 3 (ARTH)
AWS CLI

Using AWS CLI to launch an EC2 Instance - TASK 3 (ARTH)

Hey Everyone ! In AWS CSA And Developer Training by Vimal Daga Sir, we, learners, are given a task.

Task Description - AWS 

✔ 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.

All the above steps must be performed using AWS CLI.

---------------------------------------------------------------------------------------------------------------

So, let's start !!

Step 1 : Go to AWS CLI Documentation page and download it for Windows.

No alt text provided for this image

Step 2 : Create an IAM User in AWS Management Console. For this, you need an AWS account.

▶Go to services tab and search for IAM.

No alt text provided for this image

▶In IAM Dashboard, go to Users and click on Add User.

▶Give appropriate name (in capitals), select Programmatic Access and then click on Permissions.

No alt text provided for this image

▶Next, go to Attach existing policies directly and select AdministratorAccess.

No alt text provided for this image

▶Next, Add NAME Tag and give description like USERNAME in capitals.

▶Next, Click on Create User.

▶Next, Check whether user created successfully. If yes, download .csv file which contain Access Id and secret Access Id of your user.

No alt text provided for this image

Step 3 : Configuring AWS CLI in Windows.

▶Install the AWSCLIV2.msi file which we downloaded earlier.

▶Go to command prompt. Check aws version by command aws --version.

▶Type command aws configure.

▶Give Access Id and Secret Access Id from the .csv file which we downloaded earlier. In region give the aws region you are in and in output format give json.

No alt text provided for this image

Step 4 : Creating a Key Pair.

▶In command prompt, type the command aws ec2 create-key-pair --key-name ANYNAME

No alt text provided for this image

▶If we check in EC2 Dashboard in AWS Console, we will see our key pair enlisted there.

No alt text provided for this image

Step 5 : Creating a Security Group.

▶In command Prompt, type command aws ec2 create-security-group --group-name ANYNAME --description "DESCRIPTION"

No alt text provided for this image

▶We can check our created security group in AWS Console.

No alt text provided for this image

▶Then, type command aws ec2 authorize-security-group-ingress --group-name YOUR_SG_NAME --group-id YOUR_SG_ID --protocol tcp --port ANY_FREE_PORT --cidr 0.0.0.0/0 for authorizing security group with proper inbound rules(protocol, port number and IP).

Step 6 : Launching an EC2 Instance using above created key pair and security group

▶In command Prompt, type command aws ec2 run-instances --image-id ami-0e306788ff2473ccb --instance-type t2.micro --count 1 --security-group-ids YOUR_SG_ID --key-name YOUR_KEY_NAME --subnet-id YOUR_SUBNET_ID

No alt text provided for this image

▶We can check our new instance in AWS Console.

No alt text provided for this image

Step 7 : Creating an EBS Volume of 1 GB

▶In command Prompt, type command aws ec2 create-volume --availability-zone YOUR_AVAILABILITY_ZONE --size 1 --volume-type gp2

No alt text provided for this image

▶We can check our newly created EBS Volume in AWS Console.

No alt text provided for this image

Step 8 : Attaching the above created EBS Volume to the Instance we created.

▶In command Prompt, type command aws ec2 attach-volume --instance-id YOUR_INSTANCE_ID --volume-id YOUR_VOLUME_ID --device /dev/sdh

No alt text provided for this image

▶We can now check the status of volume that we created earlier.

No alt text provided for this image

---------------------------------------------------------------------------------------------------------------

In this way, We can launch an EC2 Instance via AWS CLI and also attach VOLUME to it.

This marks the end of my TASK of AWS CLI.

THANK YOU !!

Thanks for sharing informative article. Really appreciable 😊

Keeping EC2 instances in prime condition will be your bread and butter.

To view or add a comment, sign in

More articles by Palak S.

  • IBM - Ansible UseCase

    Let's discuss the fundamental knowledge about Ansible first. What is Ansible? Today's world is the World Of Automation.

  • HADOOP SPLITS DATA SERIALLY OR PARALLELLY ??

    Some Fundamental knowledge..

    2 Comments
  • HADOOP CLUSTER SETUP

    Due to the advent of new technologies, devices, and communication means like social networking sites, the amount of…

  • High Availability Structure in AWS using CloudFront

    Let's discuss some basics first. What is Cloud Computing? Cloud computing is the on-demand availability of computer…

  • AUTOMATION USING PYTHON

    Automation is the technology by which a process or procedure is performed with minimal human assistance. Automation or…

    3 Comments
  • How MNCs are getting benefits from AI/ML ?

    So, let's begin with a very basic question which must have arisen in the minds of readers who have just read the…

    2 Comments
  • Brainly : AWS Case Study

    Before talking about the Case Of Brainly, firstly I would like to discuss briefly about Cloud Computing to form a base…

  • Involvement Of Big Data In MNC's

    An intelligent analysis of data is what you need if you wish to succeed in the coming years. Success is why almost all…

Others also viewed

Explore content categories