Control EC2 Service Using CLI
In this task, we are going to perform the following:
- Create a Key Pair
- Create a Security Group
- Launch an instance using these Key Pair and Security Group
- Create an EBS volume of 1 GB
- Attach this volume to the instance that we have created
Step-1: First we have to install the AWS CLI version 2, we can use the following link to download this for windows: AWS CLI V2
For Linux use this command: curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
For MAC: AWS CLI V2 macOS
We can check that AWS installed or not by the following command
aws --version
Step-2: Configuration of AWS CLI
- First, we have to create an IAM user
- Now we have to give permission to this user. In my case, I give Administration Power to my user.
- Now finally, we get the Access Key and Secret Key.
- After this, we need to configure our AWS CLI using the CMD line. For this, we have to provide the Access Key and Secret Key
Now, we are good to go.
Step-3: Create a New Key Pair
We successfully created a private Key to launch our instance.
Step-4: Create a New Security Group
Now, we are ready to launch the instance using these Key Pair and Security Group. We use this Security Group in our instance.
Step-5: Launch the Instance
- We use the following command to launch the instance
- By providing these details we can launce the instance and we get the instance id
- We can also cross-check that the instance is created or not using GUI
Here, we can see our instance is running successfully.
Step-6: Create an EBS volume of 1 GB
- Now, we are going to create an EBS volume, to attach it with the instance, both instance and volume should be in the same Region. We can create volume by the following command
Here, we can see that we successfully created the volume and we also get the volume id.
- We can also cross-check by GUI that it is created or not
Step-7: Now, in this final step, we are going to attach this volume to the EC2 instance that we have created past
BINGO!!!!
See, we successfully attach the volume to the instance.
- We can check it from GUI also
Here, we can see that our newly created volume 'in use' right now.
THAT'S IT...
THANKS FOR READING THIS!!!