ARTH TASK 3
First we need to login and
have access to our AWS account. Now the main pre-requisites for the task
are:
✅AWS CLI should be
installed on our os.
✅ AWS CLI should be configured on our os.
After installation
of AWS CLI we can check its version on command prompt using command
aws
--version
Now for configuring AWS CLI ,
we need a user account with which we can login using its access keys and do our
tasks. As a best practice, we do not use
the AWS account root user access keys for any task where it's not required.
Instead, we must create a new administrator IAM user with access keys for ourselves.
So here for
this task I will create an IAM user named Jack . To create an IAM user :
1.
Sign in to the AWS
Management Console and open the IAM console
2.
In the navigation
pane, choose Users and then choose Add user.
3.
Type the user name
for the new user. This is the sign-in name for AWS. I am keeping the username
as Jack.
4. We will give programmatic access to this user so that we can use access keys.
5. Here we will not add this user to any group as we do not have much tasks to do. Then we will attach the existing policy PowerUserAccess to the user for our usecase.6. We can give any tag to the user, here I have given the tag Developer.7. I have not set any permission boundaries. Here we can see the review of the user below:
8. The user is successfully created and now we should download the .csv file that contains our access id and secret key . We should store this key secretly.
Now we will
configure the AWS CLI using command on Windows cmd prompt or Git bash terminal
aws configure
After
pressing enter terminal will prompt for access id, secret key , default region
, output format. We will copy paste our access id and secret key from the .csv
file which we downloaded after creating the user. We can keep the region
ans output format default.
Finally configuration done.
Step 1: Create a
key pair
$ aws ec2 create-key-pair --key-name Mytestkey --output text
We can check through GUI console that our key-pair is created.
$ aws ec2 create-security-group --group-name Mytestsg --description "Security Group created by AWS CLI" --output json
We can check through GUI console that our security group is created .
$ aws ec2 authorize-security-group-ingress --group-id sg-0531377c1d2aa0225 --protocol all --port all --cidr 0.0.0.0/0
Now we can check through the GUI console that the rule is added to the security group.
STEP 3: Launch an instance using the above created key pair and security group
Now we will create the instance using the above created key pair and security group.
To create any ec2 instance using AWS CLI we use command
$aws ec2 run-instances --image-id ami-0bcf5425cdc1d8a85 --count 1 --instance-type t2.micro --key-name Mytestkey --subnet-id subnet-a3e6efcb --security-group-ids sg-0531377c1d2aa0225 --output text
Here we can see that the instance is running.
Now we will proceed towards next step.
Step
4. Create an EBS
volume of 1 GB
Now we will create an EBS volume
of 1 GB . It is mandatory to create the ebs volumes in the same availability
zone in which the instance is launched. As volume will be available to
instances only when they are created in the same availability zone.
$ aws ec2 create-volume --availability-zone ap-south-1a --size 1 --volume-type gp2 --output json
From the GUI console we can check that our volume is created.
$ aws ec2 attach-volume --device xvdb --instance-id i-031b987e8851a4aa3 --volume-id vol-0d2be6306869f40a0 --output json
Now our EBS volume is successfully attached to the EC2 instance and here we can see there are two volumes attached, one is default and the other one is created by AWS CLI.
Finally our task is successfully completed.
Comments
Post a Comment