Building Basic AWS Cloud Infrastructure using AWS CLI
TASK DESCRIPTION :
Create the following using AWS CLI:
- 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 GiB.
- The final step is to attach the above created EBS volume to the instance you created in the previous steps.
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 CLI, we need to download and install it in our system. For this practical, we'll use Version 2. After installing, to verify if it is successfully installed or not we can check its version.
Before starting, we need aws Access key and Secret key for configuration.
- To, get them we need to go to our 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 then it'll be giving us “Access key” and “Secret key”.
We use aws configure command to setup the AWS CLI. We need to provide Access key and Secret key of IAM user for authentication also we have to mention the region name and output format.
There is no need to remember the commands, we can refer to the help.
We can easily see all the commands available for EC2 on CLI. Let's Start...
Step-1 : Create a key pair
aws ec2 create-key-pair --key-name awskey
Step-2 : Create a security group
aws ec2 create-security-group --group-name AWSscgroup --description "My Aws Cli security group" --vpc-id vpc-441de639
Now we need to add inbound rules.
aws ec2 authorize-security-group-ingress --group-name AWSscgroup --protocol tcp --port 22 --cidr 0.0.0.0/0
Step-3 : Launch an instance using the above created key pair and security group.
aws ec2 run-instances --image-id ami-038f1ca1bd58a5790 --instance-type t2.micro --key-name awskey --security-group-ids sg-0a298a35e6ee44eb7 --subnet-id subnet-946b98a5 --count 1 --tag-specifications=ResourceType=instance,Tags=[{Key=Name,Value=Cli-Instance}]
Step-4 : Create an EBS volume of 1 GiB.
aws ec2 create-volume --volume-type gp2 --size 1 --availability-zone us-east-1e --tag-specifications=ResourceType=volume,Tags=[{Key=Name,Value=myEbs-cli}]
Step-5 : Attach the above created EBS volume to the instance.
aws ec2 attach-volume --volume-id vol-004c12b22254c15ac --instance-id i-02303356cdfd40748 --device /dev/sdf
We can also verify this by checking the disks attached to the instance.
***** THANK YOU FOR READING!! *****