Building Cloud Infrastructure Using AWS CLI..

Building Cloud Infrastructure Using AWS CLI..

?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 of 1 GB.

?? The final step is to attach the above created EBS volume to the instance you created in the previous steps.

?Note- All the above steps must be performed using AWS CLI

??Why AWS CLI?

AWS CLI gives you the ability to automate the entire process of controlling and managing AWS services through scripts. These scripts make it easy for users to fully automate cloud infrastructure. Prior to AWS CLI, users needed a dedicated CLI tool for just the EC2 service.

??Installing AWS CLI :

Installation of AWS CLI is so simple. You just need to download the application from the below mentioned link and like we install any other application, just run the application and keep on clicking and it will be installed.

Once done with installation to check whether it's working or not just run the below command in your command prompt/ terminal

aws --version
No alt text provided for this image

??Configuring AWS CLI :

Before starting, we need aws access key and secret key for configuration. Because for humans we use username and password for authentication. But to authenticate any program we use access key and secret key.

  • To, get those things you need to go to your AWS account from AWS Web Console. Then go to “IAM” service => click on “Users” => then click on “Add User” and create one user.
  • Then click on “Programmatic access” and if you read the description of this access you can see, it’s giving us “access key” and “secret key”. For reference follow the below mentioned screenshot…
No alt text provided for this image
No alt text provided for this image
  • Next click on “Tags” and give any desired tag. Then click on “review” and then click on “Create User”. Next it will provide you one option to see your Access Key and Secret Key. Don't forget to “Download” the credentials by clicking on the download button for future reference.

Step 1:Login to AWS Using security credentials of IAM User we created .

To Login to AWS Cloud through AWS CLI we have command as aws configure .

aws configure
No alt text provided for this image

Step 2: Create a key pair

For creating Key Pair we have command as :

aws create-key-pair --key-name key_name --query "keyMaterial" > key_name.pem
No alt text provided for this image
No alt text provided for this image

Step 3: Create Security group

To create Security group we have the following command 

aws ec2 create-security-group --group-name AwsTrainingSecurityGroup --description "AWS Training SG" --vpc-id-167a637e
No alt text provided for this image
No alt text provided for this image

Now for updating the Security Group Rules we have the following command

aws ec2 authorize-security-group-ingress --group-id security_group_id --protocol    protocol_name --port port_no --cidr cidr_block_value


aws ec2 authorize-security-group-ingress --group-id sg-0a9a596603eff346 --group-name AwsTrainingSecurityGroup --protocol tcp --port 22 --cidr 0.0.0.0/0
No alt text provided for this image
No alt text provided for this image

Step 4: Launch one EC2 Instance using above Key pair and Security Group

To launch ec2 instance AWS CLI has command as :

aws ec2 run-instances   --security-group-ids   group_id   --instance-type _type_ --image-id ami_id   --key-name key_name  --count no_of_instance 
No alt text provided for this image
No alt text provided for this image

Step 5: Create one EBS Volume and attach it to the EC2 Instance we launched

To Create EBS Volume AWS CLI has command as :

aws ec2 create-volume --volume-type volume_type --size volume_size --availability-zone AZ_name
No alt text provided for this image
No alt text provided for this image

To Attach EBS Volume to EC2 Instance we have command :

aws ec2  attach-volume   --volume-id volume_id   --instance-id instance_id  --device device_name
No alt text provided for this image

Step 6: We have to check the EBS Volume is attached to our EC2 Instance by Connecting to EC2 Instance via SSH

By using lsblk  command we can display details about block devices and these block devices(Except ram disk) are basically those files that represent devices connected to our EC2 Instance.

No alt text provided for this image

We have successfully completed our practical and also learn how to work on AWS CLI....??

Step 7: At last we have to Terminate the EC2 Instance before that we first Detach the EBS Volume

To detach the EBS Volume we have following command :

aws ec2  detach-volume  --volume-id  volume_id

To Terminate the EC2 Instance use following command :

aws ec2 terminate-instances --instance-ids  instance_id


Thank You for investing your time for reading my Article!!!??

Excellent Work

Swarnim Kashyap

DevOps Engineer | 2x Redhat Certified | RHCE | RHCSCK | 1x AWS Certified | MLOPS

4 年

Amazing bro?? Vishal Dhole

Aaditya Tiwari

DevOps Engineer @Amdocs

4 年

Nice work ?

Chaitanya Chougule

Senior DevOps Engineer @Deltek

4 年

Great Vishal Dhole bro ? ?

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

Vishal Dhole的更多文章

社区洞察

其他会员也浏览了