Launching an Instance Using AWS CLI with EBS Volume
Amazon Web Services (AWS) is a subsidiary of Amazon providing on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis. These cloud computing web services provide a variety of basic abstract technical infrastructure and distributed computing building blocks and tools. One of these services is Amazon Elastic Compute Cloud (EC2), which allows users to have at their disposal a virtual cluster of computers, available all the time, through the Internet. AWS’s version of virtual computers emulates most of the attributes of a real computer, including hardware central processing units (CPUs) and graphics processing units (GPUs) for processing; local/RAM memory; hard-disk/SSD storage; a choice of operating systems; networking; and pre-loaded application software such as web servers, databases, and customer relationship management (CRM).
Ways To Communicate With AWS Services:-
1. WEBUI
Using the WebUI version of operating the AWS services user only can perform one task at a time and the very limited task can be done in a certain amount of time which means it takes a lot of time to launch a cluster which is not good in the terms of complexity. WebUI is simpler but slow in the terms of speed. but for beginners, it is good to use WebUI for the learning process but users need to switch to CLI for more efficient work.
2. COMMAND LINE INTERFACE(CLI)
AWS command-line interface (CLI) is an open-source tool that enables us to interact with AWS services using the command in our command-line shell. 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.
Things We Are Going To Do In This 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 created in the previous steps.
To Perform We Need:-
- AWS Account
- AWS CLI Application
Let’s Start
First login to your account and go to IAM services
And now go to users and press Add user
After clicking on Add User, a page will open fill the details as shown below, and click on the Next Permissions button.
Now add PowerUserAccess group
Configuring the AWS CLI
Enter access key and secret key in the command line to login into AWS CLI.
Now to connect to the ec2 Instance we have to create a private key. For that use the below command
aws ec2 create-key-pair --key-name <keyname>
Download the Key Pair .pem File. For this, we use the below command
aws create-key-pair --key-name key_name --query "keyMaterial" > key_name.pem
Now create a security group with this command:
aws ec2 create-security-group --descriptionSecurity_group_using_AWS_CLI --group-name MyNewSecurityGroup
So we launching an instance using the above created key pair and security group
To launch an ec2 instance AWS CLI we use the below command
aws ec2 run-instances --image-id ami-0e306788ff2473ccb --security-group-ids sg-0f2663203cd6eea86 --instance-type t2.micro --subnet-id subnet-4b493b07 --key-name testkey1
Now we are creating an EBS. For this, we use the below command
aws ec2 create-volume --availability-zone ap-south-1b --size 1 --volume-type gp2
Now attached the EBS with Ec2-instance. Command-
aws ec2 attach-volume --instance-id i-0c751c458a362a2ed --volume-id vol-0b48d3be01b773473 --device /dev/xvdh
We did it, We have launched the instance and attached the EBS using the command line interface
THANK YOU