Deploy Basic AWS Cloud Infrastructure Using AWS CLI
Bobby Singh
3x RedHat ★ 3x Microsoft ★ DevOps & Cloud Engineer ★ Solution Architecture ★ Aviatrix Certified Engineer ★ Multi hybrid Cloud ★ Jenkins ★ Kubernetes
!! ?????????? ?????????????????????? !!
Welcome you all to my article based on Creating Basic Cloud Infrastructure under the guidance of Mr. Vimal Daga Sir.
?? TASK DESCRIPTION:
?? Create a key pair
?? Create a security group
?? Launch an instance using the above created key pair and security group
?? Create an EBS volume and attach to the instance we created above
? All the above steps must be performed using AWS CLI
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 use AWS Cloud through CLI only Prerequisite is to Install the AWS CLI SDK tool.
For Installing the AWS CLI tool follow the below link:
For this, there are some Prerequisite
- An account on AWS so that we can use its resources.
- Installation of AWS CLI in our OS. Here I am going to use Windows as my base OS.
- Create an IAM User. Here I am going to create an IAM with Admin Power. The Steps are following as :
- First of all, login to AWS and go to its console window.
- Go to the IAM service and create a new user.
- Add a user name and create a password.
- Give this User admin power.
Give some tag and it is created
4. Now create a profile.
Profile: It is not a good practice to provide access key and secret key directly in the code as we use SCM tools like Github etc to manage the code. So we create a profile and give these keys.
Now come to our main Task.
Step1: Create a key pair
Now we successfully Logged into AWS Account. After these, We have to create a Private Key to connect to the ec2 Instance. For creating Key Pair we have command as :
aws ec2 create-key-pair --key-name awscsakey
Output:
We can also verify this AWS WebUI as well.
To download the Key Pair .pem File We have to Use the following command which pipes the key pair into the file.
aws create-key-pair --key-name key_name --query "keyMaterial" > key_name.pem
Step2: Create a Security Group:
A security group acts as a virtual firewall for your instance to control inbound and outbound traffic. When you create a security group, you specify a friendly name of your choice.you can have a security group for use in EC2-Classic with the same name as a security group for use in a VPC. However, you can't have two security groups for use in EC2-Classic with the same name or two security groups for use in a VPC with the same name.
Now, creating a security group this command:
aws ec2 create-security-group --description Security_group_using_AWS_CLI --group-name MyNewSecurityGroup
Output:
Now, we have our security group ready and we can see that on the console too.
To Set Inbound or Ingress Rule to authorize the outside traffic we have the command as :
aws ec2 authorize-security-group-ingress --group-id security_group_id --protocol protocol_name --port port_no --cidr cidr_block_value
Step3: Launch an instance using the above created key pair and security group:
Now, let's create an EC2 instance. This instance will have the key pair and security groups attached. To launch an ec2 instance AWS CLI has command as :
aws ec2 run-instances --image-id ami-0e306788ff2473ccb --security-group-ids sg-0f2663203cd6eea86 --instance-type t2.micro --subnet-id subnet-4b493b07 --key-name awscsakey
Output:
we can see that on the console too.
Here we can see which security group is attached to the EC2 instance.
Step4: Create an EBS volume with CLI
Now, we create a 1 Gb volume using EBS. EBS comes under the EC2 service of AWS.
The volume type will be general-purpose SSD Volume. To Create EBS Volume AWS CLI has commanded as :
aws ec2 create-volume --availability-zone ap-south-1a --size 1 --volume-type gp2
Now the EBS volume is created successfully.
Output:
Now the EBS volume is created successfully. We can see from the console also.
Step5: Attach EBS volume to EC2 instance.
This Volume we need to attach to the EC2 instance we have created earlier. To Attach EBS Volume to EC2 Instance we have commanded:
aws ec2 attach-volume --instance-id i-0edeb5cebb638dd10 --volume-id vol-0d2e880cda508a7c2 --device /dev/xvdh
Output:
Our EBS volume attached with ec2 instance successfully
Here we can see two EBS volume. one is the root volume which is attached on boot time second is that volume with is attached by us
So, this was all about my AWS CLI Task assigned to me in the ARTH- The school of Technologies.
? I would like to thanks Mr.Vimal Daga for giving such a challenging task which helps me to explore my core concepts of Cloud Computing.
??For any queries or suggestions DM me.
!! Thanking you all for visiting my article !!
Keep Sharing Keep Learning