Building Cloud Infrastructure Using AWS CLI..
Vishal Dhole
Full Stack Web Developer | Angular | Node.js | AWS | DevOps | Immediate Joiner
?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.
- To know more about AWS CLI : https://aws.amazon.com/cli/
??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.
- To download AWS CLI : https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html
Once done with installation to check whether it's working or not just run the below command in your command prompt/ terminal
aws --version
??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…
- 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
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
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
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
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
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
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
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.
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!!!??
SDE At Siemens
4 年Excellent Work
DevOps Engineer | 2x Redhat Certified | RHCE | RHCSCK | 1x AWS Certified | MLOPS
4 年Amazing bro?? Vishal Dhole
DevOps Engineer @Amdocs
4 年Nice work ?
Senior DevOps Engineer @Deltek
4 年Great Vishal Dhole bro ? ?