Launch AWS EC2 Instance & Create and Attach EBS Volume Using AWS CLI
Task:-
1. Create a key pair
2. Create a security group
3. Launch an instance using the above-created key pair and security group.
4. Create an EBS volume of 1 GB.
5. The final step is to attach the above created EBS volume to the instance you created in the previous steps.
Step 1: Create Key Pair
Create a key-pair using the below command.
Command : aws ec2 create-key-pair — key-name <Key name> > <file name>.pem
We are storing the private key in the file of extension .pem
Check whether the key pair is created or not in your AWS account
Successfully created.
Step 2: Create Security Group
A security group acts as a virtual firewall for your instance to control inbound and outbound traffic.
Command: aws ec2 create-security-group — group-name <Security Group name> — description “security group using cli”
Step 3: Launch EC2 Instance
Command : aws ec2 run-instances — image-id ami-068d43a544160b7ef — count 1 — instance-type t2.micro — key-name KeyPair_cli — security-group-ids sg-0fb22cdd3ec7df599 — subnet-id subnet-425b4f2a
Step 4: Create EBS Volume of 1 GB
Command: aws ec2 create-volume — size 1 — availability-zone ap-south-1a
Step 5: Attach The EBS Volume
Attach the above created EBS volume to your instance using the following command-
Command: aws ec2 attach-volume — volume-id <Volume ID> — instance-id <Instance ID> — device /dev/sdf
Go to instances in your AWS account, click on your instance and check in the storage whether the volume is attached or not.
Successfully Created and Attached the EBS Volume.
😊Thank you for Reading😊