Launching AWS instance using the AWS CLI
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. Attach the above created EBS volume to the instance
Let's get started, we will be performing each step one by one
Step 1: Creating a Key Pair
$ aws ec2 create-key-pair --key-name task3
Here task3 is the name for the key pair, different names can also be used.
Step 2: Create a Security Group
$ aws ec2 create-security-group --description SG --group-name task3
Here task3 is the name for the Security Group, different names can also be used.
Step 3: Launch an instance using the above created key pair and security group.
$ aws ec2 run-instances --image-id ami-0e306788ff2473ccb --count 1 --instance-type t2.micro --key-name task3 --security-group-ids sg-038501d154cab1e3e --subnet-id subnet-7c6e6f14 --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=task3}]'
Step 4: Creating an EBS volume of 1 GB
$ aws ec2 create-volume --volume-type gp2 --size 1 --availability-zone ap-south-1a
Step 5: The final step is to attach the above created EBS volume to the instance
$ aws ec2 attach-volume --volume-id vol-0f12bbb9aacc19d9d --instance-id i-0418595631b9678b6 --device /dev/sdf